Lesson 11: Identity and interchange

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.

Homomorphismpure f <*> pure x = pure (f x)
Compositionpure (.) <*> u <*> v <*> w = u <*> (v <*> w)
Identitypure id <*> v = v
Interchangeu <*> 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.

❤️1apply ( compose f g ) x = apply f ( apply g x )
❤️2apply identity x = x
❤️3If 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

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