Game, Set, Match
Around a year ago, there was a lively debate about the
type invariance of the immutable Set
in Scala. Dogpile argumentation on a subject
far outside the popular interest is of course thrilling in itself, but the topic also provides a nice focal point for
exploring and clarifying some important aspects of the Scala type system.
We recall that Scala collections (and other higher kinded classes) can be invariant, covariant or contravariant in their type parameters,
corresponding repectively to declarations as class Whatever[A]
, class Whatever[+A]
or class Whatever[-A]
.
- In the case of covariance, a
Whatever[B]
will …