Last active
December 21, 2019 00:18
-
-
Save 3v0k4/2f1f94528cc88ede56d925dc2a3b5e9c 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
generate :: Ast -> String | |
generate (Value i) = show i | |
generate (Node Add ast1 ast2) = | |
"(" <> generate ast1 <> " + " <> generate ast2 <> ")" | |
generate (Node Sub ast1 ast2) = | |
"(" <> generate ast1 <> " - " <> generate ast2 <> ")" | |
evaluate :: Ast -> Int | |
evaluate (Value i) = i | |
evaluate (Node Add ast1 ast2) = | |
evaluate ast1 + evaluate ast2 | |
evaluate (Node Sub ast1 ast2) = | |
evaluate ast1 - evaluate ast2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment