How to do it...

  1. Open src/Main.hs for editing. We will use this file for using type classes. 
  2. 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.

  1. 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 ...

Get Haskell Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.