fun icon indicating copy to clipboard operation
fun copied to clipboard

Add `curry` and `uncurry`

Open klmr opened this issue 9 years ago • 1 comments

Add curry and uncurry functions. I’m not sure they’re particularly useful to be honest but given the confusion between currying and partial application in the R community it would have a nice educational effect to contrast the two operations of currying and partial function application.

Semantics (WLOG):

  1. curry(f) returns a function that’s a curried version of f.
  2. uncurry(g) returns a function that’s an uncurried version of g.
  3. length(args(curry(f))) == 1.
  4. identical(uncurry(curry(f)), f).

Point (4) in particular might require some gymnastics if f is a closure — although strict identity is probably not required as long as the observable effect is identical.

klmr avatar Sep 28 '16 13:09 klmr

Something to think about: currying a function with an ellipsis presumably yields an infinitely recursive function. Not clear how to resolve this, maybe just forbid it.

klmr avatar Sep 28 '16 13:09 klmr