【发布时间】:2015-10-23 04:57:31
【问题描述】:
type exp = V of var
| P of var * exp
and var = string
我正在构建一个二叉引用树,其中右叶节点查找左叶节点上的那些,如果所有右叶节点都与某些左叶节点匹配,则返回 true。
let rec ctree : exp * exp -> bool
=fun (e1,e2) -> match e2 with
| P (x,y) -> match y with
| P (a,b) -> if (ctree(a,b)) then true else ctree(x,b)
| V a -> if a=x then true else ctree(e1,y)
| V x -> e1=x
但是在这里,我在第 5 行不断收到错误:
| V a -> if a=x then true else ctree(e1,y)
这里的 e1 有一个 exp 类型,应该是这样,但是编译器一直告诉我它应该是一个 var=string 类型。另外,对于第 6 行,
V x -> e1=x
它告诉我应该再次输入 var=string 而不是 e1。
谁能告诉我为什么会出现错误?
【问题讨论】:
标签: ocaml binary-tree