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?
References below are to the Scala Language Specification
Consider the following method:
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))b) the argument list is omitted, and expected type of expression is a function type (§6.25.2):
c) each of the arguments is
_(a special case of the ‘Placeholder Syntax for Anonymous Functions’ (§6.23))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 thata: Int.