Answers
- Enumeration types are defined with the syntax data
ET = K1 | … | Kn
, whereET
is the name of the type andK1
…Kn
are the names of the data constructors. Each of the constructors is a value of the enumeration type. Values can be distinguished by means of pattern matching, writing one equation of a function per constructor:f K1 = ..
…
f Kn = …
- Record types are defined with the syntax data
RT = RK {f1 :: T1, …, fn :: Tn}
, whereRT
is the name of the record type andRK
is its constructor. The fields are namedf1
...fn
and have theT1
...Tn
types, respectively. A value ofRT
is created with the syntaxRT { f1 = e1, …, fn=en}
, wheree1
...en
are expressions of theT1
...Tn
types that yield the values for the fields. Given a value of the record type, a field can be extracted by using the field name as a function,fi :: RT ->
Ti
. - An algebraic datatype is defined with the syntax data
AT = K1 T11… | … | Kn Tn1 …...