Imperative Programming TT23, Type variance
Flashcards
What does it mean for a type to be invariant?
It is neither covariant or contravariant.
What does it mean for a type $T$ to be covariant?
Whenever A <: B, we have T[A] <: T[B].
What does it mean for a type $T$ to be contravariant?
Whenever A <: B, we have T[B] <: T[A].
Can you state the Liskov substitution principle?
If S <: T then everything you can do with a value of type T, you should also be able to do with a value of type S.