Disclaimer: c at runtime is erased and your match will not work correctly. You match on I[_]
In case your Node is invariant, Node[A] is a subclass of Node[B] only if f A=B It makes
n passed test[A, B](n: Node[A => B]) to really be Node[A => B]
If you deviate, if your n matches the pattern I[Something] for any Something , then A and B must be of type Something
In case Node is covariant, due to the definition of Function1[-A,+B] you can call
test[A,B](n) where n is Node[A1 =>B1] , where A1>:A and B1<:B (equation 1)
therefore, if your n matches a I[C] , that means A1 = C and B1 = C
If you replace c with equation 1 , you get C >: A and C<:B (equation 2)
Therefore, the following assignment is no longer valid.
f: A => B = C => C
For the left side to be assigned on the right side, we need C => C be Function1[-A,+B]
This means that A >: C and B <: C , but from equation 2 we know that this does not hold (except for the case C = A and C = B, and there is no evidence if your Node is invariant )
Edmondo1984
source share