I'm a little confused by the difference in type checking between cardinal and unpainted generic functions:
scala> def x[T](a: T, b: T) = (a == b)
x: [T](a: T, b: T)Boolean
scala> def y[T](a: T)(b: T) = (a == b)
y: [T](a: T)(b: T)Boolean
My intuition was that the two x(1, "one"), and y(1)("one")should lead to the type of error, but I was wrong:
scala> x(1, "one")
res71: Boolean = false
scala> y(1)("one")
<console>:9: error: type mismatch;
found : java.lang.String("one")
required: Int
y(1)("one")
^
At first, I thought some kind of implicit casting was going on, but that doesn't seem to be the case:
scala> x(1 :Int, "one" :String)
res73: Boolean = false
So what is going on? What should be my intuition?
source
share