July 2023
Intermediate to advanced
670 pages
17h 13m
English
The last of the type class laws that we’ll look at are the laws for Applicative. Applicative has four laws, and they are a bit trickier than the laws for Functor and Monad. In particular, the names of the laws might sounds a bit more intimidating, but as we’ve seen in the last two sets of laws, we can follow the code and write tests to get a feel for how our particular instances are holding up to the laws without having to delve too deeply into the underlying mathematical theory. Let’s start with the applicative laws as they are documented in the standard library:
| | -- Identity |
| | pure id <*> v = v |
| | -- Composition |
| | pure (.) <*> u <*> v <*> w = u <*> (v <*> w) |
| | -- Homomorphism |
| | pure f <*> pure x = pure (f x) |
| |