Question 1 . The surprise to me is that type inference succeeds at all. Another case that fails to compile is
val spam = x => log(log(x))
Typically, the rule is that parameter types (here, x ) must be explicitly specified. But, obviously, this rule does not hold for the special case x => f(x) , which is rewritten to f _ . In other contexts, this rewriting leads to unspecified behavior .
Note. If the expected type of function exists, then the type of the parameter should not be explicit,
val spam: Double => Double = x => log(log(x))
Question 2 . Without a space, you came across the "operator" syntax for types. Here is an example that compiles,
trait =-[A, B] trait One def eggs(foo: Int=-One) = foo
It is equivalent
def eggs(foo: =-[Int, One]) = foo
The error message you received (expected identifier, but ...) says that integer literal 1 not a valid type.
source share