#include "prelude.h" #include using std::cout; using std::endl; template class AddHelper { F f; G g; public: AddHelper(const F& an_f, const G& a_g) : f(an_f), g(a_g) {} template struct Sig : public FunType::ResultType> {}; template typename F::template Sig::ResultType operator()( const I& i ) const { return f(i)+g(i); } }; struct Add { template struct Sig: public FunType > {}; template AddHelper operator() (F f, G g) const { return AddHelper(f,g); } } add; int main() { cout << add(curry2(Plus(),3), curry2(Plus(), 6))(7) << endl; Compose2 my_compose2; cout << my_compose2(Plus(), curry2(Plus(),3), curry2(Plus(), 6))(7) << endl; Fun2 f = makeFun2(monomorphize2(Plus())); cout << f(3,5) << endl; // Test automatic currying. cout << (f(3))(5) << endl; // Really test automatic currying! f is treated as a function of 1 argument // (in which case it returns a function of one argument). When it is // curried explicitly, it becomes a 0-argument function returning a 1-arg // function. Fun0 > g = makeFun0(curry1(f, 5)); cout << g()(3) << endl; }