Contents
- The identity law
- Fantastic violation
- Map violation
- The (>>) type
- Relationship to fmap
- The interchange law
- The right-sectioned operator
- Shape-preserving mappings
- A Maybe with two Nothings
- A forgetful List
In the last session, we discussed two of the four Applicative laws.
☑ | Homomorphism | pure f <*> pure x = pure (f x) |
☑ | Composition | pure (.) <*> u <*> v <*> w = u <*> (v <*> w) |
☐ | Identity | pure id <*> v = v |
☐ | Interchange | u <*> pure y = pure ($ y) <*> u |
For three venerated properties of functions, we posed the question: Is pure
a homomorphism that preserves them all? We have seen that the composition law ensures the first. Identity and interchange will provide the other two.
☑ | ❤️1 | apply ( compose f g ) x = apply f ( apply g x ) |
☐ | ❤️2 | apply identity x = x |
☐ | ❤️3 | If apply f x = apply g x for all x , then f = g |
Recall that in the Applicative context, we assume these definitions:
- identity is
pure id
- apply is
(<*>)
- compose is
\f g -> pure (.) <*> f <*> g