我正在尝试编写一个模块,将 x:int = if true then 3 else 5 转换为字符串
这是我到目前为止的代码
module Ast =
struct
type typ = Bool | Int
type var = A | B | C | D | E | F
type exp = Const of int * typ
| App of string * exp list
| If of exp * exp * exp
| And of exp * exp
| Or of exp * exp
| Id of var * typ * exp
let rec toString (t) =
let formatDec1(va,ty,e) = ???
match t with
Const(n, _) -> print_int n
| App(id, [e1; e2]) -> formatter(" " ^ id ^ " ", e1, e2)
| App(id, [e1]) -> formatter(" " ^ id ^ " ", e1, Const(0, Int))
| App(id, _) -> formatter(" " ^ id ^ " ", Const(0, Int), Const(0, Int))
| If(e1, e2, e3) -> formatIf(e1, e2, e3)
| And(e1, e2) -> formatter(" && ", e1, e2)
| Or(e1, e2) -> formatter(" || ", e1, e2)
| Id(va,ty,e) -> formatDecl(va,ty,e)
end
我仍然是 OCaml 的初学者,找不到任何关于在线转换为字符串的信息。谢谢!