Lesson 10: Homomorphism and composition

  • 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:

  1. Homomorphism: pure f <*> pure x = pure (f x)
  2. Composition: pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
  3. Identity: pure id <*> v = v
  4. 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.

Sign up for access to the full page, plus the complete archive and all the latest content.