Lesson 8: An applicative Map

Contents
  • Lists and maps
  • Maps as functions
  • Lifting a function over Map
  • The pure problem
  • The (>>) applicative
  • Following the rules
  • Coming up

We have so far seen with applicative functors that one way to view the Applicative class is that its most notable methods, liftA2 and <*>, are extensions of fmap: liftA2 is fmap with extra arguments, and <*> is a partially-applied liftA2. So, most functors are also applicative functors. This does not, however, account for pure, which has no companion in the Functor class.

In this lesson we’re going to look at why an important data structure called Map is not a valid instance of Applicative. To do that, we’ll consider an alternative to Map alongside Map itself, what their instances would look like, and the problem with pure. This will involve discussion of one of the Applicative laws.

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