Untitled
Anonymous
ocaml
11/10/2021 6:32 PM
428 B
25
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...