Ruby Currying(khelll.com)10 points·by batasrki·17 ปีที่แล้ว·4 commentskhelll.comRuby Curryinghttp://www.khelll.com/blog/ruby/ruby-currying/3 commentsPost comment[–]raganwald·17 ปีที่แล้วreplyAs mentioned elsewhere, is this currying? Or partial application?Currying:lambda { |x,y| x + y }.curry => lambda { |x| lambda { |y| x + y } }Partial Applicationlambda { |x, y| x + y }.apply(2) => lambda { |y| 2 + y }And given #curry, #apply is trivial:class Proc; def apply(param); self.curry.call(param); end end...or at least, that's my understanding...[–]grandalf·17 ปีที่แล้วreplyi think you're right.[–]grandalf·17 ปีที่แล้วreplyAfter learning about these concepts in Haskell, the Ruby code seems downright ugly (I never thought I'd say that)... but still probably quite useful in some cases.[–]khelll·17 ปีที่แล้วreplyraganwald, u r totally right, i have updated the post to show the diff.
Currying:
lambda { |x,y| x + y }.curry => lambda { |x| lambda { |y| x + y } }
Partial Application
lambda { |x, y| x + y }.apply(2) => lambda { |y| 2 + y }
And given #curry, #apply is trivial:
class Proc; def apply(param); self.curry.call(param); end end
...or at least, that's my understanding...