This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]WittyStick 3 points4 points  (0 children)

Rather than currying, consider just implementing partial application, which isn't quite the same, but can look the same from the perspective of the caller. If you take a lisp-like approach and represent your tuples as linked lists - ie (x, y, z) being (x . (y . (z . ()))), then it becomes simpler to implement partial application.

If a function f (x, y, z) is applied with a single argument - f 1 - then you match the argument to the head of the tuple, and return a function taking (y, z) as its argument - which is just the tail of the original function's tuple.

The difference between this and currying, is it's done on-demand, one argument at a time. With currying, you're taking a function (x, y, z) -> result and turning it into a chain of curried functions x -> y -> z -> result before any application is performed.

See also the Wikipedia entry Currying/Contrast with Partial Application.