I am diving in FP concepts using Scala. I think that I've finally understood what covariance and contravariance are and why function types are contravariant in their argument types and covariant in their return types. But there is still somethig that I don't understand. In Scala, a List[+A]
has a prepend (+:
) method that takes an S
where S >: A
. If the type was an A
, the compiler would throw an error: covariant parameter in contravariant position, I don't understand why the fact of declaring a List[+A]
makes A
covariant in the function definition. As far as I understand, covariance and contravariance relates to more complex types than A
, that is, monads or functions.
Scala list: http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.List