Monoid is an important and very useful type class. A Monoid assumes two behaviors:
- There is a default or empty value of the data type.
- Given two values of the data type, they can be combined to create a single value.
The simplest example of a Monoid is Integer. We can define an empty value of an Integer as 0. We can then use addition as an operation to combine two Integers. In this recipe, we will define a data type Option and define an instance for Monoid.