Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For "Box[+T]", can I say "The type Box is covariant", is it correct?

Say I defined a type constructor Box:

trait Box[+T]

What is correct?

  1. type Box is covariant
  2. type constructor Box is covariant
  3. type parameter T is covariant
  4. type parameter T in type constructor Box is covariant
  5. If all of them are incorrect, what's the correct expression?
like image 873
Freewind Avatar asked Jun 16 '14 07:06

Freewind


1 Answers

About variance from the book Functional Programming in Scala:

In the declaration trait List[+A], the + in front of the type parameter A is a variance annotation which signals that A is a covariant or “positive” parameter of List. This means that, for instance, List[Dog] is considered a subtype of List[Animal] , assuming Dog is a subtype of Animal.

like image 73
Artsiom Miklushou Avatar answered Nov 15 '22 05:11

Artsiom Miklushou