3 ms·
I'm not an experienced Haskell programmer, but I've never seen someone use different names for the type and the type constructor, as in: data IntAndChar =
by Xophmeister 9y ago
I'm not an experienced Haskell programmer, but I've never seen someone use different names for the type and the type constructor, as in:
data IntAndChar = MkIntAndChar Int Char
They belong to different namespaces, so you can use the same name:
data IntAndChar = IntAndChar Int Char
Indeed, I believe this is preferred as it reduces the programmer's cognitive load.
- efnx 9y agoIt's common convention to keep them the same, but in this case it may be useful to distinguish between the type and the term level value.
- weavie 9y agoThis seems to be the convention in Idris where data IntAndChar = IntAndChar Int Char would not compile with Main.IntAndChar already defined.
- deleted 9y ago[deleted]
- runeks 9y agoIn this case, I think the different name for the constructor was chosen specifically to show the difference between the term and type level. I think it's a good idea, when explaining Haskell, to not assume that no one gets confused by the constructor and type having the same name (it confused me to begin with).