#include using std::cout; using std::endl; #include using std::string; #define FCPP_ENABLE_LAMBDA #include "prelude.h" using namespace fcpp; typedef string S; void print( S s ) { cout << s << endl; } int main() { int x = 3; int y = 4; int z = x ^plus^ y; cout << z << endl; Fun0 hello = curry( ptr_to_fun(&print), S("hello") ); cout << "-------" << endl; ByNeed xt( before( hello, const_(3) ) ); ByNeed yt( 4 ); LambdaVar<1> X; LambdaVar<2> Y; cout << "-------" << endl; ByNeed zt = lambda()[ xt %bind% lambda(X)[ yt %bind% lambda(Y)[ unitM()[ X %plus% Y ] ] ] ](); cout << "-------" << endl; cout << zt.force() << endl; cout << zt.force() << endl; cout << "-------" << endl; xt = ByNeed( before( hello, const_(3) ) ); zt = lambda()[ compM()[ X %plus% Y | X<=xt, Y<=yt ] ] (); cout << "-------" << endl; cout << zt.force() << endl; cout << zt.force() << endl; { cout << "-------------------" << endl; // expensive negate Fun1 exp_neg = before( curry( ptr_to_fun(&print), S("expensive") ), negate ); int z = plus( exp_neg(3), 4 ); cout << z << endl; cout << "-------" << endl; ByNeed bx( 3 ); ByNeed by( 4 ); ByNeed bz( liftM2()(plus)( liftM()(exp_neg)(bx), by ) ); cout << "..." << endl; cout << bz.force() << endl; cout << "-------------------" << endl; bz = ByNeed( before( hello, const_(0) ) ); cout << liftM3()(ignore(plus))(bz,bx,bDelay(4)).force() << endl; } { cout << "==========" << endl; Fun1 p = before( hello, plus(1) ); zt = lambda()[ compM()[ X %plus% Y | X<=bLift(p)[3], Y<=yt ] ] (); //X<=bDelay[p[3]], Y<=yt ] ] (); cout << "==========" << endl; cout << zt.force() << endl; cout << zt.force() << endl; cout << "==========" << endl; Fun2 p2 = before( hello, plus ); zt = lambda()[ compM()[ X | X<=bLift(p2)[3][4] ] ] (); cout << "==========" << endl; cout << zt.force() << endl; cout << zt.force() << endl; cout << "==========" << endl; Fun3 p3 = before( hello, ignore(plus) ); zt = lambda()[ compM()[ X | X<=bLift(p3)[1][3][4] ] ] (); cout << "==========" << endl; cout << zt.force() << endl; cout << zt.force() << endl; cout << "==========" << endl; Fun0 p0 = before( hello, curry2(plus,3,4) ); zt = lambda()[ compM()[ X | X<=bLift(p0)[_*_] ] ] (); cout << "==========" << endl; cout << zt.force() << endl; cout << zt.force() << endl; cout << "==========" << endl; } }