In Scala, why can't I partially apply a function without explicitly specifying its argument types?
scala
Solution
References below are to the Scala Language Specification
Consider the following method:
def foo(a: Int, b: Int) = 0
Eta Expansion can convert this to a value of type `(Int, Int) => Int`. This expansion is invoked if:
a) `_` is used in place of the argument list (Method Value (§6.7))
val f = foo _
b) the argument list is omitted, and expected type of expression is a function type (§6.25.2):
val f: (Int, Int) => Int = foo
c) each of the arguments is `_` (a special case of the 'Placeholder Syntax for Anonymous Functions' (§6.23))
val f = foo(_, _)
The expression, `foo(_, 1)` doesn't qualify for Eta Expansion; it just expands to `(a) => foo(a, 1)` (§6.23). Regular type inference doesn't attempt to figure out that `a: Int`.
Problem
This produces an anonymous function, as you would expect (f is a function with three arguments): ``` f(_, _, _) ``` What I don't understand is why this doesn't compile, instead giving a "missing parameter type" error: ``` f(_, _, 27) ``` Instead, I need to specify the types of the underscores explicitly. Shouldn't Scala be able to infer them given that it knows what the function f's parameter types are?