Content deleted Content added
Remove poorly worded and misguiding sentence about using `dynamic` in C# to circumvent static typing and work around variance |
→Formal definition: Resolve clarification needed by switching to same notation used in body. Also add sentence to explicitly define the notation. Tag: nowiki added |
||
Line 16:
== Formal definition ==
{{More citations needed section|date=November 2021}}
Suppose <code>A</code> and <code>B</code> are types, and <code><nowiki>T<U></nowiki></code> denotes application of a [[type constructor]] <code>T</code> with type argument <code>U</code>.
Within the [[type system]] of a programming language, a [[typing rule]] for a type constructor <code>I</code> is:
* ''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>
* ''variant'' if covariant, contravariant or bivariant;
* ''invariant'' or ''nonvariant'' if not variant.
|