An Introduction to Monoids in Haskell
Monoids are a simple algebraic structure in which operations can be composed. The Haskell programming language features a typeclass with the same name that is very closely modeled after the mathematical notion. The class provides a standard mechanism to compose operations over a range of types.
Why Care about Monoids in Programming?
It should be obvious but let me reference one particular impact. The famous Ruby on Rails web-framework features composition of SQL statements in an algebraic way1. I highly recommend the reading of Magic Scaling Sprinkles - Why Arel? where the author describes the motivation behind creating the framework. While the effort was ignited in a different context (Scheme, through the seminal Wizard Book), the mentioned "closure under composition" is nothing but a monoidal structure2.
It is recommended to have basic knowledge about types and classes in Haskell. It would also be beneficial to know how functions, including their type signature, fit into the system.
Here we go
The clip doesn't contain any sound. This is quite deliberate for several reasons. You should adjust the playback speed to your needs and pause when you need to contemplate. It would be annoying and disruptive if the video included sound.
Where to go from Here
The official GHC Data.Monoid documentation is a concise reference. The accompanying source code is quite enlightening. A very concise yet thorough introduction to Haskell is given in Hutton's book Programming in Haskell; however, monoids are not covered. Monoids are treated in an own chapter in Lipovača's book Learn You a Haskell for Great Good!. They also appear briefly in Real World Haskell.
About this Series
This is the first contribution of a series.