정상 나무에 대한 참조로 나무를 변환 :OCaml이 나는 나무의 2 종류를 가지고
내가 그들을 포함 된 목록에 대한 참조로 저장 이웃과 나무를 가져오고를 출력하는 기능convert: ref_tree -> tree
를 작성하려면
type ref_tree = Node of int * ref_tree list ref
type tree = Node of int * tree list
트리에서 참조가 일반 목록으로 변경됩니다.
let rec convert t =
match t with
| Node (x, l) ->
if (!l = []) then Node (x, []) else
Node (x, (List.map convert !l))
을하지만, 컴파일 할 때 OCaml의 오류를 반환 : 여기에 내가 시도 무엇
if (!l = []) then Node (x, []) else
Error: This expression has type 'a list
but an expression was expected of type tree list ref
경우 Node (x, [])
빈 내부 목록에서 This expression
점. 왜 형식 불일치가 있습니까?