Are these two function declarations effectively different?
If not, why do they have different toString values?
scala> def f: (Int) => Int = x=> x*x
f: (Int) => Int
scala> def f(x: Int) = x*x
f: (Int)Int
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first is a no-argument method
f1that returns aFunction1[Int, Int].The second is a one argument method
f2that takes an anIntand returns anInt.You can invoke f1 and f2 with the same syntax, although when you call
f1(2)it is expanded tof1.apply(2).Finally, you can ‘lift’ the method
f2to a function as follows.Exercise: What is the type of
f1 _?