How and why does 'val' and 'case' affect the type system? (Especially the variance)
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class E[-A]
defined class E
scala> class F[-A](val f: E[A] => Unit)
<console>:6: error: contravariant type A occurs in covariant position in type => (E[A]) => Unit of value f
class F[-A](val f: E[A] => Unit)
^
scala> case class C[-A](f: E[A] => Unit)
<console>:6: error: contravariant type A occurs in covariant position in type => (E[A]) => Unit of value f
case class C[-A](f: E[A] => Unit)
scala> class F[-A](f: E[A] => Unit)
defined class F
Consider this:
If
f
is not visible outsideF
, this problem can't happen.