14
Why does the Scala 2.11.0-M3 compiler give me error: identifier expected but integer literal found. when the round brackets () are used while it compiles fine with curly brackets {}?
$ scala
Welcome to Scala version 2.11.0-M3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val s = "this is a string"
s: String = this is a string
scala> s.toList map (c:Char => 1)
<console>:1: error: identifier expected but integer literal found.
s.toList map (c:Char => 1)
^
scala> s.toList map {c:Char => 1}
res7: List[Int] = List(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
Somehow it compiles fine with the round brackets as well when the left-hand side of the anonymous function is within another pair of the round brackets. Why?
scala> s.toList map ((c:Char) => 1)
res8: List[Int] = List(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)