Created
April 2, 2018 10:44
-
-
Save mwolicki/8a1cb133e4d8fa7158a9b4a559f900c1 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
type Op = | |
| Add of (Op * Op) | |
| Mul of (Op * Op) | |
| Divide of (Op * Op) | |
| Substract of (Op * Op) | |
| Value of int | |
let mul a b = Mul (a, b) | |
let sub a b = Substract (a, b) | |
let v = Value | |
let rec eval = function | |
| Add (Eval (+) value) | |
| Mul (Eval (*) value) | |
| Divide (Eval (/) value) | |
| Substract (Eval (-) value) | |
| Value value -> value | |
and (|Eval|) op (a, b) = op (eval a) (eval b) | |
//× − 5 6 7 | |
let example = | |
mul (sub (v 5) (v 6)) (v 7) | |
|> eval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment