scala> def x(s:Int, t:Int) = s+t
x: (s: Int, t: Int)Int
scala> def x2(s:Int)(t:Int) = s+t
x2: (s: Int)(t: Int)Int
scala> def x3(s:Int) = (t:Int) => s+t
x3: (s: Int)Int => Int
scala> (x(_,_)).curried
res0: Int => Int => Int = <function1>
scala> (x2(_:Int)(_:Int)).curried
res4: Int => Int => Int = <function1>
scala> x2(_)
res13: Int => Int => Int = <function1>
scala> x3(_)
res19: Int => Int => Int = <function1>
scala> x2(1)(2)
res11: Int = 3
scala> x3(1)(2)
res10: Int = 3
scala> res0(1)(2)
res8: Int = 3
scala> res4(1)(2)
res9: Int = 3
scala> res13(1)(2)
res16: Int = 3
scala> res19(1)(2)
res20: Int = 3
Although by the classical functional programming concepts of currying and partial functions x2, x3, res0, res4, res13 and res19 all of them are same, but they are still so different in Scala.
What could be the reason behind this approach which could be very intimidating to the newbies?Could it be the burden of supporting object-oriented concepts like method overriding via inheritance where method signature plays an important role?
One thing is sure that Scala's syntax design is very poor and full of gotchas.
No comments:
Post a Comment