all after reading Scala covariance / contravariance question and its answer provided by Daniel Spiewak,and Section 19.3-19.7 of book "Programming in Scala", I have another confusion about the definion of Function1[-A, +B]: why its first type parameter is contravariant? I got one reason, it is that this type parameter guarantees that the subtypes always appear earlier than supertypes when there are multiple cases, at the same time, subtype "is a" supertype. for example:
class A
class B extends A
class C extends B
scala> val withDefault: A => B = {
| case x:B => new B
| case x:A => new B }
withDefault: A => B = <function1>
here, (1) case x:B
is earlier than case x:A
, (2) Function1[A,B] <: Function1[B,B]
and there must be other reasons? any message will be appreciated!