The sum types are equivalent to variant (or union in C). However, sum type in Haskell is much more than that. It is also called tagged union. The simplest sum type is Bool, which can take two values True and False. In this recipe, we will define simple sum types and use them in our example.
Defining a sum type
Getting ready
Create a project called sum-type using the Stack simple template:
stack new sum-type simple
How to do it...
- Open src/Main.hs for editing.
- Add the following data type for representing the days in a week:
data Days = Sunday | Monday | Tuesday...