Transformers and deriving
Contents
- Setup
- Type alias
- ReaderT
- Newtype
- Generalized newtype deriving
- Deriving via
This article introduces two topics:
- Monad transformers
- GHC’s extensions for typeclass deriving
We successively refactor an example, first introducing a very typical application of ReaderT, then cleaning up the code with two approaches for deriving Monad.
The final code uses the via deriving strategy to elegantly extract a monad instance from the transformers library without introducing any extra complication to our example’s type definitions.

