Untitled

mail@pastecode.io avatar
unknown
ocaml
2 years ago
319 B
0
Indexable
Never
exception UnexpectedString

type exp =
    Flt of float
  | Str of string
  | Neg of exp
  | Add of exp * exp
  | Mult of exp * exp;;

let rec eval = function
    Str _ -> raise UnexpectedString
  | Flt x -> x
  | Neg x -> -. eval x
  | Add (x, y) -> eval x +. eval y
  | Mult (x, y) -> eval x *. eval y;;