July 2023
Intermediate to advanced
670 pages
17h 13m
English
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 ...
Read now
Unlock full access