我下面有代码,但没有得到想要的正确结果
type expr
= Val of value
| App of expr * expr
| MultiApp of expr * expr list
and value
= Int of int
| Bool of bool
let rec t(e:expr) : expr = match e with
| Val _ -> e
| App(f,a) -> App(t f, t a)
| MultiApp(f,[]) -> raise (Failure "no")
| MultiApp(f,lst) -> match lst with
|[]-> raise (Failure "no")
|x::xs -> let rest = MultiApp(f,xs) in
App(f,x)
let e1 = Val(Int 1)
let e2 = Val(Int 3)
let e3 = Val(Bool true)
let e4 = Val(Bool false)
例如
MultiApp(fe,[e1;e2;e3])
应用有趣t
之后,它会得到类似
App(App(App(t fe, t e1), t e2) t e3)