0
에 배 함수를 사용하여 목록에 이진 트리를 변환 :이 주어 OCaml의
type 'a tree = Empty | Node of 'a * 'a tree * 'a tree
사용 :
let rec tree_fold f e t = match t with
| Empty -> e
| Node (x, l, r) -> f x (tree_fold f e l) (tree_fold f e r);;
이 목록에 이진 트리를 변환합니다. 예.
let someTree = Node (1,Node(2,Node(3,Empty,Empty),Empty),Empty)
tree2list someTree
은 [1;2;3]
이된다.
내 시도 :
This expression has type 'a list but an expression was expected of type 'b -> 'b .
나는 시간이에 있었다 유사한 오류가 계속했습니다
let tree2list tr = match tr with
| Empty -> Empty
| Node (x,l,r) -> (tree_fold (fun acc tree-> tree::acc) [] tr)
이 오류를 제공합니다. 조금이라도 도움이된다면 큰 도움이 될 것입니다.
감사합니다.