Lesson 5: The Reader context

Contents
  • An exciting opportunity
  • The function instance
    • pure
    • liftA2
    • (<*>)
  • Introducing Reader
  • Example revisited
  • Coming up

A long time ago, in a lesson far, far away, we talked about the Functor for the function type – or, more precisely, for (->) a, the partially applied function type. Because the function type itself has the wrong kind for a Functor, it has to be partially applied, in the same way as Either or (,) has to in order to have a viable fmap. Looking carefully at the type of fmap instantiated to that type (->) a led us to the revelation that the fmap is identical to ordinary function composition.

In this lesson, we’ll be talking about the function type again and looking at its Applicative instance. It turns out that the function’s functors, from Applicative and Monad through Profunctor, are extremely useful. For the purposes of Applicative, Monad, and monad transformers, we usually refer to it with a newtype wrapper called Reader, so we’ll be taking our first look at that in this lesson as well.

Sign up for access to the full page, plus the complete archive and all the latest content.