Co-, contra-, and invariance

Folks often refer to the component of a functor’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.