Last active
January 29, 2017 14:27
-
-
Save deque-blog/c2ee7a05a64df116e96338303d6b4ed5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename A, typename M> | |
auto fmap(M map, expression_r<A> const& e) | |
{ | |
using B = decltype(map(std::declval<A>())); | |
using Out = expression_r<B>; | |
if (auto* o = get_as_add(e)) | |
return Out(add_op<B>(o->rands() | transformed(map))); | |
if (auto* o = get_as_mul(e)) | |
return Out(mul_op<B>(o->rands() | transformed(map))); | |
if (auto* i = get_as_cst(e)) return Out(*i); | |
if (auto* v = get_as_var(e)) return Out(*v); | |
throw_missing_pattern_matching_clause(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment