[Boost.Bind] and [Boost.Lambda] problem with partial application and curry
I've been working on implementing some functional idioms in C++ in order
to help me learn the Boost.Bind, Boost.Lambda and Boost.Function libraries.
I have this (which uses Boost.Bind)
#include
Kirit Sælensminde:
template< typename R, typename V1, typename V2 > boost::function< boost::function< R ( V1 ) > ( V2 ) > curry( boost::function< R ( V1, V2 ) > f ) { return boost::bind( papply< R, V1, V2 >, f, _1 ); }
...
boost::function< boost::function< int ( int ) > ( boost::function< int ( int, int ) >, int ) > fpapply( papply< int, int, int > );
...
//curry( fpapply );
Terrific.
It seems that fpapply is of the form function
Peter Dimov wrote:
Kirit Sælensminde:
template< typename R, typename V1, typename V2 > boost::function< boost::function< R ( V1 ) > ( V2 ) > curry( boost::function< R ( V1, V2 ) > f ) { return boost::bind( papply< R, V1, V2 >, f, _1 ); }
...
boost::function< boost::function< int ( int ) > ( boost::function< int ( int, int ) >, int ) > fpapply( papply< int, int, int > );
...
//curry( fpapply );
Terrific.
As in inducing terror? :)
It seems that fpapply is of the form function
(V2,V3), and curry wants function (V2).
The argument to curry is a binary function of this form: boost::function< R ( V1, V2 ) > fpapply is of this type: boost::function< boost::function< int ( int ) > ( // curry's R boost::function< int( int, int ) >, // curry's V1 int ) > // curry's V2 papply itself is this: boost::function< R ( V2 ) > papply( // curry's R boost::function< R ( V1, V2 ) > f, // curry's V1 V1 v ) // curry's V2 These are in the same form, it's just that V1 is now a function rather than a value. To me it looks like I should be able to pass this in as the binary function to curry. K
Kirit Sælensminde wrote:
http://www.kirit.com/Blog:/2007-09-10/What%20do%20you%20get%20when%20you%20c...
FWIW, Boost.Lambda can curry on the fly. // \x -> (\y -> add(x, y)) bind( __bind__, &add, _1, protect(_1) ) __bind__ is an "imaginary" function object which represents bind itself. If interested in implementation, See: lambda_bind @ http://tinyurl.com/2ekf9q Regards, -- Shunsuke Sogame
shunsuke wrote:
Kirit Sælensminde wrote:
http://www.kirit.com/Blog:/2007-09-10/What%20do%20you%20get%20when%20you%20c...
FWIW, Boost.Lambda can curry on the fly.
// \x -> (\y -> add(x, y)) bind( __bind__, &add, _1, protect(_1) )
__bind__ is an "imaginary" function object which represents bind itself.
If interested in implementation, See: lambda_bind @ http://tinyurl.com/2ekf9q
That's really neat. It looks like you've already done in Egg a lot of the stuff I was going to start going through as well, for example, during the last week I'd been thinking about what you have as fuse and unfuse. I'd also been thinking about generic lazy and memoize higher order functions. What is the status of Egg? K
participants (3)
-
Kirit Sælensminde
-
Peter Dimov
-
shunsuke