0
我有递归函数,当然树如何通过递归函数的值树
type tree = Node of bool ref * (char * tree) list ref
type cours= tree ->char list -> char list* char list * tree
let cours t word=
let rec cours_tree t word l1 l2=match t,word with
| Noeud(r,n),[] -> Noud (r,n), l1 , l2
| Noeud (r,n),x::h when (List.mem_assoc x !n) ->
x::l1,cours_tree (List.assoc x !n) h l1 l2
| Noeud (r,{content=(c,b)::n),x::h ->
x::l2,cours_tree (List.assoc x b) h l1 l2
in
cours_tree t word [] []
我希望它可以从人物的特定列表浏览树的分支,并返回子树到达,人物名单和那些无法到达的人的名单; 但我发现了一个错误:
Error: This expression has type char list * 'a
but an expression was expected of type 'a
The type variable 'a occurs inside char list * 'a#
我不知道哪里是我的问题。
你为什么要取消IVG的编辑?这个'Noud'是什么?如果我把它改成'Noeud',我没有你的错误,我有一个语法错误:'Syntax error:pattern expected' here:'Noeud(r,{content =(c,b):: n),' 。 请编辑你的代码,这样人们可以得到你有错误,如果你想要一个答案。 – Lhooq