'MetaCons
describes a constructor'MetaCons
contains information about a single constructor of a type.
'MetaCons constructorname fixity isrecord
parameter | meaning |
---|---|
constructorname | The name of the constructor. For data Id = MkId this is MkId |
fixity | The constructor’s fixity |
isrecord | 'True if this constructor is a record: data Rec = Rec { field : Int } |
The fixity
parameter is only relevant for constructors made up entirely out of symbols.
NonEmpty
is one example of a type that uses such a constructor:
data NonEmpty a = a :| [a]
The name of NonEmpty
‘s single constructor is :|
.
Because it’s made up entirely of symbols Haskell allows us to write it in between its arguments,
and calls such functions infix operators.
The ‘fixity’ field provides information about how strongly the constructor binds its arguments.
Haskell uses this information to figure out where to put the parens in expressions with multiple operators like this:
1 :| [2, 3] <> [4, 5]