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

@Define what it means for a type to be invariant.

It is neither covariant nor contravariant.

@Define what it means for a type $T$ to be covariant.

Whenever A <: B, we have T[A] <: T[B].

@Define what it means for a type $T$ to be contravariant.

Whenever A <: B, we have T[B] <: T[A].

@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