(* op_t : 2項演算子の型 *) type op_t = Plus | Minus | Times | Divide (* 2項演算子を文字列にする関数 *) (* op_to_string : op_t -> string *) let op_to_string op = match op with Plus -> " + " | Minus -> " - " | Times -> " * " | Divide -> " / " (* Syntax.t : プログラムを表す型 *) type e = Num of int | Var of string | Op of e * op_t * e | Fun of string * e | App of e * e | Control of string * e | Prompt of e (* プログラムを文字列にする関数 *) (* Syntax.to_string : Syntax.t -> string *) let rec to_string exp = match exp with Num (n) -> string_of_int n | Var (x) -> x | Op (e0, op, e1) -> "(" ^ to_string e0 ^ op_to_string op ^ to_string e1 ^ ")" | Fun (x, e) -> "(fun " ^ x ^ " -> " ^ to_string e ^ ")" | App (e0, e1) -> "(" ^ to_string e0 ^ " " ^ to_string e1 ^ ")" | Control (x, e) -> "(control " ^ x ^ " -> " ^ to_string e ^ ")" | Prompt (e) -> "prompt (" ^ to_string e ^ ")" (* プログラムをプリントする関数 *) (* Syntax.print : Syntax.t -> unit *) let print exp = let str = to_string exp in print_string str