sumtype.cd 330 Bytes
Newer Older
1 2 3 4 5
type Expr = 
    (`add, Expr, Expr)
  | (`mul, Expr, Expr)
  | (`sub, Expr, Expr)
  | (`div, Expr, Expr)
6
  | Int
7
 
8
let eval ( Expr -> Int )  
9 10 11 12 13 14
  | (`add,x,y) -> eval x + eval y
  | (`mul,x,y) -> eval x * eval y
  | (`sub,x,y) -> eval x - eval y
  | (`div,x,y) -> (eval x) div (eval y)
  | n -> n 
in
15
eval (`add, 10, (`mul, 20, 5))