Co-, contra-, and invariance

⇐ Notes archive

(This is an entry in my technical notebook. There will likely be typos, mistakes, or wider logical leaps — the intent here is to “let others look over my shoulder while I figure things out.”)

Folks often refer to the component of a function’s “polarity.” “The input is in the negative position.” “The output is positive.”

And that made me wonder, is there a, well, neutral polarity?

Maybe that’s when a component is in both a negative and positive position, canceling one another out.

Let’s see what happens.

A -> ….

A is in a negative position? Check. Let’s add it to the positive spot.

A -> A.

This is our old friend, Endo! At the bottom of the file, I noticed imap and asked some folks what the “i” stood for. Turns out it’s short for, “invariant,” which reads nicely in that both co- and contravariance net out to invariance.

Pairing functor type, variance(s), and *map name:

  • Functor, covariant, map.
  • Functor, contravariant, contramappullback.
  • Bifunctor, covariant (and I’m guessing contra-, maybe both working in the same direction is what matters?), bimap.
  • Invariant functor, invariant (co- and contravariant in the same component), imap.
  • Profunctor, co- and contravariant along two components, dimap.