KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I wrote a mathematical Vector module in Haskell. So I started out with: data Vector a = Vector !a !a !a deriving (Eq, Show) Fine—this lets me use any numerical data type I want. The problem is that I don't want to be writing Double and Vector Double everywhere for the simple reason that I shouldn't have to. So I add: type Scalar = Double type Vector = Vector Scalar But of course that second line is wrong, since there are now two declarations of Vector . So what should I change it to? I think to myself, no, I'm going to be writing this all over my code, so I want to leave the type alias simply as Vector . Which means I have to change the data type name. But if I change that, then I feel like I should also change the constructor, which makes everything more confusing. But if it feels awkward making the constructor have the same name as the type alias this way. Right now I have this: type Scalar = Double type Vector = VectorT Scalar data VectorT a = Vector !a !a !a deriving (Eq, Show) I picked T arbitrarily (I guess it stands for "type") but I'm not so sure about this. Normally when I document functions I would say -- Calculate the magnitude of a Vector , but with VectorT I feel like I should really be using that type name. So I resort to just referring to them as vectors (not capitalized)—except then I feel like I have to apply this convention to every comment for every data type. Has anyone been in a similar situation? Can anyone think of a more elegant solution in this case?
Tags (comma-separated)
Save Edits
Cancel