In Python I can do this:
In [24]: def m1():
....: return "I am legend"
....:
In [25]: f1 = m1
In [26]: type(f1)
Out[26]: function
In [27]: type(m1)
Out[27]: function
while in Scala,
def m1() = "I am legend"
the equivalent of what I did above is not
val f1 = m1
but I instead have to specify
scala> val f1:()=> String = m1
f1: () => String = <function0>
or
scala> val f1 = m1 _
f1: () => String = <function0>
Why was this design choice made ? As someone coming to Scala from Python, being able to assign a function via
val f1 = m1
seems much more natural than having to do one of the approaches above.
I know that val f1 = m1
results in m1
being called and the resulting value assigned to f1
but wouldn't it have been clearer to follow the Python approach
and require the parenthesis in this case instead i.e.
val f1 = m1()
in the case where I wish to call the function and assign the result to f1
?