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>
f1
in the REPL shows the value statically bound tof1
while evaluatingf2
andf3
show the result of invoking those methods. In particular, a newFunction1[Int, Int]
instance is produced every time eitherf2
orf3
is invoked, whilef1
is the sameFunction1[Int, Int]
forever. – Randall Schulz