Earlier quoted context omitted.
That's interesting, but you did not answer my question. I wanted to know how Scala determines where to insert =>. In my example, Scala interprets "ary.map(f(_ * 2))" as "ary.map(f(x => x * 2))" (both of these expressions yield the same error). If it interpreted it the other way, then the expression would work (using your definition of f). Perhaps a better example to use would have been: Array((_:Int) * 2) ==> (x:Int)…
> In my example, Scala interprets "ary.map(f(_ * 2))" as "ary.map(f(x => x * 2))" I think this is where I'm not communicating what I'm trying to say very well. What I'm trying to say is that that statement is false. The underscore isn't a placeholder saying "inject a Function here". You probably didn't mean that exactly of course, but it's a programming language; it pays to be a bit pedantic I think. It's easier to u…
It is. Look at the error message:
error: missing parameter type for expanded function ((x$1) => x$1.$times(2))
It did inject a function, it's right there, in plain text. Then it did type inference. I mean, what else is "lifting" the asterisk to a Function supposed to mean, if not injecting a function around a placeholder? And what about "1 + _ * 2"? What is it lifting? The asterisk? No. It is lifting more than that.> You had a Function[Int,Int] before, but now that you've passed that function value to Array.apply instead of getting an Array[Function[Int,Int]] as you would in every single other case, you get a Function[Int,Array[Int]]?
That's besides the point. The question is, when the parser sees "_", how much of the context does it grab along with it? In other words, I know it's lifting stuff, what I want to know is how much it lifts. Here's another example:
f(_, 2)(3)
==> x => (f(x, 2)(3)) ?
==> (x => f(x, 2))(3) ?
Scala does the former. That's a legitimate choice given common use cases, but the latter is simpler, preserves the invariant that "a(b) (a)(b)" and has use cases as well, e.g. to make an expression like "f(super_long_expression, 2)" more readable.> But not so much as you think. It's just the "lift". Type-inferencing lets you get away with what looks like a little more sometimes.
I still don't see what type inference has to do with this. The error message makes it clear that the lift is done before type inference kicks in. In a dynamic language, you would stop at the lift, but it would otherwise work just the same.