A composite data type is constructed from other types. The most common composite data types in Haskell are lists and tuples.
We’ve already seen the list type mentioned earlier in the Strings and Characters, where we found that Haskell represents a text string as a list of Char values, and that the type “list of Char” is written [Char].
head function returns the first element of a list:
tail, returns all but the head of a list:
tail *** Exception: Prelude.tail: empty list
As you can see, we can apply
tail to lists of different types. Applying
head to a [Char] value
returns a Char value, while applying it to a
[Bool] value returns a Bool value. The
head function doesn’t care what
type of list it deals with.
Because the values in a list can have any type, we call the list type polymorphic. When we want to write a polymorphic type, we use a type variable, which must begin with a lowercase letter. A type variable is a placeholder, where we’ll eventually substitute a real type.
We can write the type “list of
a” by enclosing the type variable
in square brackets: [a]. This amounts to
saying, “I don’t care what type I have; I can make a list with
We can now see why a type name must start with an uppercase ...