Parametric ADTs
In this section, we integrate parametric polymorphism in algebraic datatypes.
Tuples
Haskell already has several parametric datatypes built in. A common family of these are generic record types, where the types of the fields are parameters, known as tuples.
If we were to define such tuple types ourselves as ADTs, we would probably write something like this:
data Tuple2 a b = MkTuple2 a b data Tuple3 a b c = MkTuple3 a b c data Tuple4 a b c d = MkTuple4 a b c d …
However, the actual built-in tuple types come with a special syntax, following the mathematical notation for tuples. The type names are written as a pair of parentheses with a comma-separated list of type parameters between them:
(a,b) (a,b,c) (a,b,c,d) …
Tuple values are written with essentially the same syntax:
*Main> :t ('a',True) ('a',True) :: (Char,Bool)
The ('a',True)
tuple value has the...