- Open src/Main.hs for editing. We will use this file for using type classes.
- Define a data type Month to describe a month in a year:
data Month = January | February | March | April | May | June | July | August | September | October | November | December deriving Show
Note that we have still used automatic derivation from Show. We will illustrate Show later in the recipe.
- Next, implement the Enum class. The Enum class is responsible for generating a list of consecutive integers and expressions such as [1..10]. The Enum class provides this behavior by associating with Integer. Create an instance of the Enum class for the data type Month. Essentially, we need to implement two functions, toEnum and fromEnum, to convert from ...