Lesson 29. Lists as context: a deeper look at the Applicative type class
After reading lesson 29, you’ll be able to
- Explain the formal definition of the Applicative type class
- Represent parameterized types as either containers or contexts
- Use List as a context to explore nondeterministic computing
In the preceding lesson, you learned how to use the <*> (pronounced app) operator to extend the power of Functor’s <$> (pronounced fmap) operator. In this lesson, you’ll take a closer look at the Applicative type class. You’ll explore the difference between types that represent a container and types that represent a context. You’ll finish by looking at the powerful things you can achieve by using lists as a context.
Consider this
A breakfast place offers you the choice of the following:
- Coffee or tea
- Eggs, pancakes, or waffles
- Toast or a biscuit
- Sausage, ham, or bacon
What are all the possible meals you could choose, and how can you use List to help?
The Applicative type class allows you to use functions that are inside a context, such as Maybe or IO. As you saw in the preceding lesson, this extends the power of the Functor type class. Because of the way that Applicative works with Functor, Functor is a superclass of Applicative. See figure 29.1.
Figure 29.1. Functor is the superclass of applicative. Figure 29.2 provides the definition of Applicative with its two required methods.
