Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active January 30, 2017 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/658b17eb18b3510dfca334230766e62f to your computer and use it in GitHub Desktop.
Save deque-blog/658b17eb18b3510dfca334230766e62f to your computer and use it in GitHub Desktop.
expression e = add({
cst(1),
cst(2),
mul({cst(0), var("x"), var("y")}),
mul({cst(1), var("y"), cst(2)}),
add({cst(0), var("x")})
});
//Initial expression
std::cout << cata<std::string>(print_alg, e) << '\n';
//Will output
"(+ 1 2 (* 0 x y) (* 1 y 2) (+ 0 x))"
//Optimized expression
auto o = cata<expression>(optimize_alg, e);
std::cout << cata<std::string>(print_alg, o) << '\n';
//Will output
"(+ (* y 2) x 3)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment