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

  1. data Maybe a = Just a
  2. | 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.

  1. data List a = Cons a (List a)
  2. | Empty