This chapter covers:
- Defining the applicative functor algebraic structure
- Grasping the relationship, differences and tradeoffs between applicatives and monads
- Proving applicative laws of identity, associativity and naturality
- Defining the traversable functor and its uses
- Combining, fusing and nesting traversable structures
- Monad composition using the monad transformer
In the previous chapter on monads, we saw how a lot of the functions we’ve been writing for different data types and combinator libraries can be expressed in terms of a single interface, Monad
. Monads provide powerful functionality as we’ve seen by the fact that we can use flatMap
to write what seems like an imperative program in a purely functional way.
In this chapter, we’ll learn about a related abstraction, the applicative functor, which is less powerful than the monad, but more general (and hence more common). The process of arriving at applicative functors will also provide some insight into discovering such abstractions, and we’ll use some of these ideas to uncover another useful abstraction, the traversable functor. It may take some time for the full significance and usefulness of these abstractions to sink in, but you’ll see them popping up again and again in your daily work with FP if you pay attention.