Creating Polymorphic Types
Get introduced to the creation of polymorphic types using examples from the Prelude.
We'll cover the following...
So far, all the types that we created have been concrete types. But just like polymorphic functions, we can also create polymorphic types. We will study them in the context of types for better error handling.
The Maybe
type
A polymorphic type is a type which contains one or more type variables. It can be seen as a recipe to create types by substituting the type variable with a concrete type.
As a first example, let’s look at the Maybe
type from the Haskell Prelude that represents optional values. Its definition is
data Maybe a = Nothing | Just a
On the left side of the equation, there is the type ...