O'Reilly logo

Learn You a Haskell for Great Good! by Miran Lipovaca

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

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

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