Boost logo

Boost :

From: Kirit Sælensminde (kirit.saelensminde_at_[hidden])
Date: 2008-01-16 21:45:24

shunsuke wrote:
> An example of currying in Egg:
> int plus(int x, int y)
> {
> return x + y;
> }
> typedef result_of_curry2<int (*)(int, int)>::type T_curried_plus;
> T_curried_plus const curried_plus = BOOST_EGG_CURRY2(&::plus);

The template type for the result of curry is a useful utility. Do you
need the arity of the function in the name though? Can this not be done
through template specialisation, or does that get too hairy on a few

It might also be nice if it took the function type in the same way that
boost::function does, i.e. int (int, int) rather than int (*)(int, int).

And finally, does the curry function itself need to be a macro? Here is
my implementation of curry2. I'd always assumed that a complete
implementation would overload on the relevant "callable" types:

template< typename R, typename V1, typename V2 >
boost::function< R ( V2 ) > papply( boost::function< R ( V1, V2 ) > f,
V1 v ) {
        return boost::bind( f, v, _1 );
template< typename R, typename V1, typename V2 >
boost::function< boost::function< R ( V2 ) > ( V1 ) > curry(
boost::function< R ( V1, V2 ) > f ) {
        return boost::bind( papply< R, V1, V2 >, f, _1 );

BTW, I implemented it like this to show the relationship between partial
application and currying more clearly.

> If interested enough, it might be enqueued to the review queue.
> Anyway, comments are most welcome.

I do hope so. I'm surprised that nobody has replied to queue it up
already :(

BTW, I really like the library name. I hope you keep it as is :)



Boost list run by bdawes at, gregod at, cpdaniel at, john at