Saturday, 15 January 2011

currying - Partial application of curried constructors in Scala -



currying - Partial application of curried constructors in Scala -

consider following:

class a(foo: int)(bar: int)(baz: int) object a{ def apply(foo: int)(bar: int)(baz: int) = new a(foo)(bar)(baz) }

with apply method can following:

scala> a(1)(2)(3) res12: script.a = script$a@7a6229e9 scala> a(1)_ res13: int => (int => script.a) = <function1>

why can't following:

scala> new a(1)_ <console>:21: error: missing arguments constructor in class new a(1)_ ^

am missing syntax wise? thought constructors meant methods on class, should lifted functions when needed (much apply method above)

calling new on class supposed create instance of class (a in case), trying new a(1) _ create instance of class without finish info contractor, not logical @ all. writing a(1) _ right , logical cause in case lifting method function (apply method companion object) has info create instance of class.

scala currying

No comments:

Post a Comment