Let's take a look at apply
without it's body:
def apply[B](f: B => String, v: String)
That reads "apply
is a function (method) parameterized on a type B
, that takes a function from B
to String
, and a String
".
Think of B
as a type variable; it will need to be instantiated at some point. That point is not the declaration of apply
. It is when apply is, well, applied to ;-)
By this contract, usage like this must be allowed:
def g(i: Int): String = "i is " + i
apply(g, "foo") // Here the type variable `B` is "instantiated" to the type Int,
But given that you have a body like f(v)
, just substituting, we see the contradiction:
Substitute
f(v)
With
g("foo") // can't compile; g takes a B, which is an Int