Algebraic Data Types
Algebraic Data Types
Using algebraic data types we are saying some datatype can be one of the many things, distinguished by and identified by what is called a constructor.
For example, Maybe a is saying that If something has type Maybe a, it can either be a value which has an a type and wrapped by a constructor Just or an empty value Nothing
data Maybe a = Just a
| Nothing
Another example is List, from its definition we can see that it has a recursive structure. So we can have whatever number of elements in our list, but they have to have the same type.
data List a = Cons a (List a)
| Empty
