Monoids and Foldables
In this and the coming chapters, we change gear from Haskell language features to Haskell programming/design patterns. These patterns are ways of structuring commonly occurring programming problems or situations and communicating about them to other Haskell programmers. Although they show some similarities with the classical object-oriented (OO) design patterns that were introduced by the Gang of Four (GoF), there are many differences as well.
Firstly, while OO programming (OOP) design patterns were devised by software engineers for software engineers, Haskell’s patterns are essentially concepts drawn from the mathematical fields of abstract algebra and category theory repurposed for (functional) programming. Besides being an astounding use of abstract mathematics in otherwise non-mathematical day-to-day programming, this has a number of consequences:
- OOP design patterns came about in a somewhat ad hoc fashion in the last 30-35 years. In contrast...