English question: co-/contra-/invariant "over" or "in"?

Continuing the discussion from Why the life time is equal?:

Which is the correct way to say it in English:

  • &'a mut T is covariant in 'a but invariant in T
  • &'a mut T is covariant over 'a but invariant over T

The reference uses both here. Maybe both are fine?

1 Like

Intererstingly, the Subtyping and Variance - The Rustonomicon only uses *variant over.
I think both are equally applicable.

1 Like

I think both are fine and the same (but my only experience is via Rust so I don't know if there a prevailing terminology is outside of contexts like this forum).


Wikipedia uses exclusively "*variant in".

1 Like

It's two different approaches to the set theory. By my understanding, it's probably marginally more correct to say that you're "(in)variant over" a generic type(set), and "(in)variant in" a polymorphic type(set), but the two can essentially be used interchangeably and trying to assign differing meanings to the two phrases is misguided at best.

Why? If the type variable is a single type within a set, you're "variant over" the single type, allowing it to be different types from the set. If the type is a set, you're "variant in" that typeset, accepting members from that set. It's a matter of perspective. The same way covariance/contravariance or universal/existential are duals across the function boundary.


The article also features “on”.

  • IEnumerable<Cat> is a subtype of IEnumerable<Animal>. The subtyping is preserved because IEnumerable<T> is covariant on T.
  • Action<Animal> is a subtype of Action<Cat>. The subtyping is reversed because Action<T> is contravariant on T.
  • Neither IList nor IList<Animal> is a subtype of the other, because IList<T> is invariant on T.

I also see a lot of “**variant in the first parameter” and other instances of “**variant in the …” where the “in” is followed by “the” and an indirect description, not directly the “name”[1] of an argument itself. It even once does “the type (A -> (B -> C)) is covariant in the position of A” notably saying “in the position of A” instead of “in A”. My takeaway is that this Wikipeida article, too, has) feature a very divers collection of ways of saying the same thing.

  1. even though, since these arguments are positional, calling is a “name” wouldn't even be accurate ↩︎

1 Like

I think "in" is more common in category theory and differential geometry.

Thinking how I would attempt to express it in German ("invariant bezüglich"?), another option might be to say:

  • invariant regarding T

But I'm not familiar with the mathematical implications and terminology.

The closest mathematical English expression would probably be "invariant with respect to T", variously abbreviated as "invariant w.r.t. T", "invariant w/r/t T", "invariant wrt T", or "invariant WRT T".

Personally, I just use "over" and "in" interchangeably, leaning toward "over" since that's what the Rust Reference uses.

1 Like

I was just thinking to myself that "in/co/contravariant with respect to (w.r.t.) some set" works, is the same across all 3, and that makes it easier to remember.
Apparently the same is true in German :slightly_smiling_face:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.