Given three ways of expressing the same function f(a) := a + 1:
val f1 = (a:Int) => a + 1
def f2 = (a:Int) => a + 1
def f3:(Int => Int) = a => a + 1
How do these definitions differ? The REPL does not indicate any obvious differences:
scala> f1
res38: (Int) => Int = <function1>
scala> f2
res39: (Int) => Int = <function1>
scala> f3
res40: (Int) => Int = <function1>
f1is a function that takes an integer and returns an integer.f2is a method with zero arity that returns a function that takes an integer and returns an integer. (When you typef2at REPL later, it becomes a call to the methodf2.)f3is same asf2. You’re just not employing type inference there.