Contents
- The homomorphism law
- Fantastic functors
- Breaking the homomorphism law
- The composition law
- Review: The tuple Applicative
- A bad Semigroup
- Recursive generation
- Breaking the composition law
We care about the laws because we want to ensure that function application in the context of Applicative behaves exactly as we expect function application to work.
The Applicative laws, once more, are:
- 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
The gist of the laws, considered together, is that an Applicative
context is a beautiful interlacing of two components: pure function application and a monoidal “effects” layer, and these are independent of each other. Functions lifted into an Applicative
context still behave like functions, and the functions do not influence the effects.