This a limitation of the implicit parameters. The get bound to the next enclosing parens. Here println() which doesn't provide an argument.
It seems that the Scala compiler purges the redundant parens in println (_) so that this acts as println _, which is OK by the rules of implicit params
Carsten
On Jan 10, 2008 9:33 AM, Michael Pradel <
michael@...> wrote:
Hi,
why doesn't the following compile:
object TypeInfer {
def main(args: Array[String]) {
val l = "a" :: "b" :: "c" :: Nil
l.foreach(println(_)) // compiles
l.foreach(println(_ + "xyz")) // doesn't compile
}
}
I expected the type of the second _ to be at least as easy to infer as
that of the first. However, I get:
TypeInfer.scala
:5: error: missing parameter type
l.foreach(println(_ + "xyz")) // doesn't compile
Thanks,
Michael