Advertisement
Guest User

Untitled

a guest
Mar 6th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type Expr =
  2.     |Const of int
  3.     |Var of string
  4.     |Add of Expr * Expr
  5.     |Sub of Expr * Expr
  6.     |Mul of Expr * Expr
  7.     |Div of Expr * Expr
  8.  
  9. let rec calc expr =
  10.     match expr with
  11.     |Const a -> a
  12.     |Add(a, b) -> calc a + calc b
  13.     |Sub(a, b) -> calc a - calc b
  14.     |Mul(a, b) -> calc a * calc b
  15.     |Div(a, b) -> calc a / calc b
  16.  
  17. calc (Add((Const 1)(Const 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement