Skip to content

Instantly share code, notes, and snippets.

@mwolicki
Created April 2, 2018 10:44
Show Gist options
  • Save mwolicki/8a1cb133e4d8fa7158a9b4a559f900c1 to your computer and use it in GitHub Desktop.
Save mwolicki/8a1cb133e4d8fa7158a9b4a559f900c1 to your computer and use it in GitHub Desktop.
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