Why can't Scala infer the type of _?

Viewed 297

I heard in Scala I can use _ as "anonymous parameter" in anonymous function:

List(1,2,3).foreach(print(_))

But this code can't be compiled:

scala> def a[T](s: Seq[T]): Seq[T] = s.map(_)
<console>:7: error: missing parameter type for expanded function ((x$1) => s.map(x$1))

And this can:

scala> def a[T](s: Seq[T]): Seq[T] = s.map(x => x)
a: [T](s: Seq[T])Seq[T]

It seems about type inference. But how could x => x provide more information than _?

2 Answers
Related