I’m a bit confused by the difference in type-checking between curried and uncurried 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 both x(1, "one") and y(1)("one") should give type errors, 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 there was some sort of implicit casting going on, but that didn’t seem to be the case:
scala> x(1 :Int, "one" :String)
res73: Boolean = false
So what’s going on? What should my intuition be?
I think that in the first case it is upcasting (downcasting?) both arguments such that T:Any. In the second, it is currying for Int, and then failing on the String.
This seems to bear me out: