Created
December 17, 2018 20:28
-
-
Save jackmott/df2b5a1d73c77062eb69f1faa63544ca to your computer and use it in GitHub Desktop.
ConstantFolding
This file contains 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
let rec ConstantFolding node = | |
match node with | |
| Add (l,r) -> match (ConstantFolding(l),ConstantFolding(r)) with | |
| (Constant v1,Constant v2) -> Constant(v1+v2) | |
| (optL,optR) -> Add(optL,optR) | |
| Sub(l,r) -> match (ConstantFolding(l),ConstantFolding(r)) with | |
| (Constant v1,Constant v2) -> Constant(v1-v2) | |
| (optL,optR) -> Sub(optL,optR) | |
| X -> X | |
| Constant v -> Constant(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment