Imperative Programming TT23, Type variance


Flashcards

What does the notation

A <: B

mean in Scala?

$A$ is a subtype of $B$.

What is the notation for a covariant type $T$ in Scala?

+T

What is the notation for a contravariant type $T$ in Scala?

-T

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.

Proofs




Related posts