Say I defined a type constructor Box
:
trait Box[+T]
What is correct?
T
is covariantT
in type constructor Box
is covariantAbout variance from the book Functional Programming in Scala:
In the declaration
trait List[+A]
, the+
in front of the type parameterA
is a variance annotation which signals that A is a covariant or “positive” parameter ofList
. This means that, for instance,List[Dog]
is considered a subtype ofList[Animal]
, assumingDog
is a subtype ofAnimal
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With