12
Monad Transformers
This chapter shows how the functionality of different monads can be combined into a single monad. Creating such combinations is relatively straightforward for applicative functors. We have seen that two different constructions can be used for this purpose – products and compositions. Unfortunately, neither works for monads. The product of two monads is not a monad and the composition of two monads is not a monad.
For the first few years of Haskell’s existence, there was no other way to create custom monads with combined effects than to write them from scratch. This involved a lot of boilerplate and required substantial expertise. Hence, researchers have long sought a way to make it possible to combine existing monads. This ...
Get Soar with Haskell 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.