Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module rec Expr : sig
- type expr =
- | Num of int
- | Add of expr * expr
- | Mul of expr * expr
- | Seq of Stmt.stmt * expr
- val eval : expr -> int
- end = struct
- type expr =
- | Num of int
- | Add of expr * expr
- | Mul of expr * expr
- | Seq of Stmt.stmt * expr
- let rec eval = function
- | Num k -> k
- | Add (e, f) -> eval e + eval f
- | Mul (e, f) -> eval e * eval f
- | Seq (s, e) ->
- Stmt.run s ;
- eval e
- end
- and Stmt : sig
- type stmt =
- | Print of string
- | Compute of Expr.expr
- | Exit
- val run : stmt -> unit
- end = struct
- type stmt =
- | Print of string
- | Compute of Expr.expr
- | Exit
- let run = function
- | Print msg -> print_endline msg
- | Compute e -> Printf.printf "%d\n" (Expr.eval e)
- | Exit -> exit 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement