Chapter 12. Monoids

This chapter features another useful and fun type class: Monoid. This type class is for types whose values can be combined together with a binary operation. We’ll cover exactly what monoids are and what their laws state. Then we’ll take a look at some monoids in Haskell and how they can be of use.

First, let’s take a look at the newtype keyword, because we’ll be using it a lot when we delve into the wonderful world of monoids.

Wrapping an Existing Type into a New Type

So far, you’ve learned how to make your own algebraic data types by using the data keyword. You’ve also seen how to give existing types synonyms with the type keyword. In this section, we’ll look at how to make new types out of existing data types by using the

Get Learn You a Haskell for Great Good! 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.