【发布时间】:2020-06-04 07:58:00
【问题描述】:
let rec fold_inorder f acc t =
match t with
| Leaf -> acc
| Node (l, n, r) -> f (fold_inorder f acc l) (f n (fold_inorder f acc r))
我正在尝试按如下方式打印树的折叠:
fold_inorder (fun acc x -> acc @ [x]) [] (Node (Node (Leaf,1,Leaf), 2, Node (Leaf,3,Leaf))) = [1;2;3]
我收到一条错误消息,提示我的 [x] 是
This expression has type 'a list
but an expression was expected of type 'a
The type variable 'a occurs inside 'a list
我真的不知道从这里做什么。任何人都可以将我推向正确的方向吗?
【问题讨论】:
标签: functional-programming ocaml