
On 08/23/2011 09:38 PM, Eric Niebler wrote:
After playing around with functional languages, I've come to envy how easy they make it to curry functions. Call a 2-argument function with 1 argument and you get a function that takes 1 argument. Pass another argument and it evaluates the function. Simple. In contrast, C++ users have to use binders, which are not as nice.
On a lark, I implemented a wrapper that turns any TR1-style function object into a "curryable" function object (attached). Successive function call invocations bind arguments until enough arguments are bound to invoke the wrapped function. With it you can do the following:
curryable<std::plus<int> > p; auto curried = p(1); int i = curried(2); assert(i == 3);
Is there any interest in such a thing?
It could be argued that Phoenix actors should be doing this. I also asked a lot of time ago for an easy function to turn a pfo into a phoenix actor, which I think would make phoenix much more ubiquitous. assuming that function was called lazy, and Phoenix did currying automatically, you could do int i = (lazy(std::plus<int>)(1) + 4)(3) assert(i == 1+3+4)