O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with Monoid

Monoid is an important and very useful type class. A Monoid assumes two behaviors:

  1. There is a default or empty value of the data type.
  2. 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 IntegersIn this recipe, we will define a data type Option and define an instance for Monoid.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required