Covariance and contravariance (computer science): Difference between revisions

Content deleted Content added
Line 16:
* ''covariant'' if it preserves the [[subtyping|ordering of types (≤)]], which orders types from more specific to more generic: If <code>A ≤ B</code>, then <code>I<nowiki><A> ≤ I<B></nowiki></code>;
* ''contravariant'' if it reverses this ordering: If <code>A ≤ B</code>, then <code>I<nowiki><B> ≤ I<A></nowiki></code>;
* ''bivariant'' if both of these apply (i.e., if <code>A ≤ B</code>, then <code>I<nowiki><A> ≡ I<B></nowiki></code>, );<ref>This only happens in a pathological case. For example, <code>type 'a t = int</code>: any type can be put in for <code>'a</code> and the result is still <code>int</code>{{Clarify|date=October 2021|reason=What syntax is this?}}</ref>
* ''variant'' if covariant, contravariant or bivariant;
* ''invariant'' or ''nonvariant'' if not variant.