Effectful Haskell: Reader, Transformers, Typeclasses
Here we’ll be looking at Reader, starting with a common use case – accessing application configuration – and working our way to effectful bliss, starting from first principles.
Once we’re there, we’ll examine how we can add other types to our context, like IO and other monads, using monad transformers.
We’ll also learn how we can design functions that operate on the exact subset of monadic functionality we want, by constraining to the particular typeclass (e.g., MonadReader, MonadIO) exposed by a given transformer.
I was really struggling with grokking the Reader monad. I had been banging away with examples in GHCI, and I was clearly using the Reader monad without truly understanding what I was doing and, more critically, why I should be doing things that way. This article, made something click in my head finally, and the feeling of mental relief has me wanting to praise Stuart's work to everyone I know.
Unfortunately, I'm the only person I know learning Haskell. (This is presumably the precise reason I have a blog.)
Effectful Haskell: Reader, Transformers, Typeclasses by Stuart Popejoy