Data, we can define new types rather than just synonyms for already existing ones. Types declared with
dataare called algebraic, referencing "sum" and "product". In data types "sum" is alteration (
A | B, meaning
Bbut not both), and "product" is combination (
A B, meaning
Suitis the type constructor in this definition, and the values (
Clubs) are data constructors. It states that the new type
Suitcan have one of the four values (the
|symbol stands for "or"). This means
Suitis a sum-type, which is any type that has multiple possible representations. Another example of a sum-type would be
Boolwhich can be either
Hearts | Diamonds / True | Falseare all examples of data constructors that have zero arguments - nullary data constructors. Likewise, type constructors can have zero or more arguments.
Boolare examples or nullary type constructors.
ConfigErroris a nullary type constructor, and its data constructors are
ConfigErrorFileNotFound FilePath, and
ConfigErrorFileNotFound FilePathis a unary data constructor meaning that it actually holds some data, in this case of type
FilePath. Nullary type constructors we have seen so far contain no data aside from their names.