#include "cppmonad.h" int ef0(int x) { return x + 1; } Vec ef1(int x) { return Vec { x - 1, x, x + 1 }; } Maybe ef2(int x) { return x % 2 ? x : Maybe(); } Either ef3(int x) { return x % 2 == 0 ? Either(x) : Either("not even"); } int main() { Vec va = mreturn>(10); Vec vb = Vec { 1, 2, 3, 4 }; Maybe ma = 3; Maybe mb; Either ea = 42; Either eb = 43; Function f0 = ef0; Function > f1 = ef1; Function > f2 = ef2; Function > f3 = ef3; auto f = fmap(f3, f0); std::cout << show(fmap(f0, va)) << std::endl << show(fmap(f0, ma)) << std::endl << show(fmap(f0, mb)) << std::endl << show(ma >> mb) << std::endl << show(vb >> va) << std::endl << show(ea >>= f3) << std::endl << show(eb >>= f3) << std::endl << show((ma >>= f2) >>= f2) << std::endl << show((va >>= f1) >>= f1) << std::endl; }