//Purpose: // Use monad to do haskell type list comprehension // as demonstrated here: // // http://www.muitovar.com/monad/moncow.xhtml#list // // Actually, the document: // // http://www-static.cc.gatech.edu/~yannis/fc++/fcpp-lambda.pdf // // gives some example of list comprehension; hence, I only need // to mimic that to test the ideas. There even may be some example // files using compM (the list comprehension monad mention around // p. 23 of fcpp-lambda.pdf). // //ChangeLog: // 2009-06-17: // cp'ed some code from monad.cc downloaded in: // FC++-clients.1.5.tar.gz // from: // http://sourceforge.net/project/downloading.php?group_id=140353&filename=FC%2B%2B-clients.1.5.tar.gz // on: // 2009-05-11.0938 // #include #include #define FCPP_ENABLE_LAMBDA #include "prelude.h" using namespace fcpp; using std::cout; using std::endl; int main() { LambdaVar<1> X; LambdaVar<2> Y; cout << "---------:" << __LINE__ << endl; { List > l = lambda() [ compM() [ makePair[X,Y] | (X <= list_with(1,2)) , (Y <= list_with(3,4)) ] ](); while( !null(l) ) { cout << head(l).first << "," << head(l).second << endl; l = tail(l); } } cout << "---------" << endl; return 0; }