もにゃど!
・・・モナドはわかりません
「計算を合成して、より複雑な計算を行う」のだとか
う〜む・・・誰か解説してください
これはリストモナドというらしい
#include <iostream> #include <iterator> #include <algorithm> #define BOOST_FCPP_ENABLE_LAMBDA #include <boost/fcpp/prelude.hpp> using namespace boost::fcpp; int main() { lambda_var<1> X; lambda_var<2> Y; list<int> ls = lambda() [ comp_m<list_m>() [ X %plus% Y | X <= list_with<>()(1,2,3), Y <= list_with<>()(2,3), guard[ X %less% Y ] ] ](); // 1+2,1+3,2+3 std::copy(ls.begin(), ls.end(), std::ostream_iterator<int>(std::cout, "\n")); // 3, 4, 5 return 0; }
#include <iostream> #define BOOST_FCPP_ENABLE_LAMBDA #include <boost/fcpp/prelude.hpp> using namespace boost::fcpp; int main() { lambda_var<1> X; lambda_var<2> Y; list<std::pair<int, int> > ls = lambda()[ comp_m<list_m>()[ make_pair[X,Y] | X<=list_with<>()(1, 2), Y<=list_with<>()(3, 4) ] ](); for (list<std::pair<int, int> >::iterator it = ls.begin(); it != ls.end(); ++it) std::cout << it->first << "," << it->second << std::endl; // 1,3 // 1,4 // 2,3 // 2.4 return 0; }