Untitled

 avatar
unknown
ocaml
3 years ago
319 B
3
Indexable
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;;
Editor is loading...