Applying Applicatives
Now that you’ve seen several different examples of types that can have a lawful Functor instance, let’s move on and take a look at Applicative:
| class Functor f => Applicative f where |
| pure :: a -> f a |
| |
| infixl 4 <*> |
| (<*>) :: f (a -> b) -> f a -> f b |
One thing that is new here is the use of => to define a constraint as part of our type class definition. This works just like it does when you use type constraints in functions. In this case, it allows us to express that anything that can be an instance of Applicative must also provide an instance for Functor. We won’t see any examples of this until later chapters, but you can also introduce constraints when you define instances.
The Applicative type class ...
Get Effective Haskell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.