
On 08/23/11 14:38, 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?
Hi Eric, I downloaded then renamed curryable.h to currable.hpp (so my emacs editor would select c++ mode). I also made corresponding changes in source "curryable.h" -> "curryable.hpp". I'm using boost 1.46 and compiling the result gives an errors: In file included from /home/evansl/prog_dev/boost-svn/ro/boost_1_46_0/boost/preprocessor/iteration/detail/iter/forward2.hpp:50:0, from ./curryable.hpp:157, from /home/evansl/prog_dev/boost-svn/ro/boost_1_46_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:47, from curryable.hpp:113, from curryable.cpp:1: ./curryable.hpp:117:1: error: macro "BOOST_PP_CHECK_2" requires 2 arguments, but only 1 given ./curryable.hpp:117:1: error: macro "BOOST_PP_CHECK_2" requires 2 arguments, but only 1 given ./curryable.hpp:117:1: error: pasting ")" and "BOOST_PP_CAT" does not give a valid preprocessing token ./curryable.hpp:175:1: error: macro "BOOST_PP_CHECK_2" requires 2 arguments, but only 1 given ./curryable.hpp:175:1: error: macro "BOOST_PP_CHECK_2" requires 2 arguments, but only 1 given ./curryable.hpp:175:1: error: pasting ")" and "BOOST_PP_CAT" does not give a valid preprocessing token In file included from /home/evansl/prog_dev/boost-svn/ro/boost_1_46_0/boost/preprocessor/iteration/detail/iter/forward2.hpp:55:0, What should I do to avoid those errors? TIA. -Larry