I (이 방법이 더 간단 할 수 있다는 사실을 무시하세요)OCaml에서 일치 레코드를 패턴 화하는 방법은 무엇입니까?
type tKey = Key of int;;
type tBST = Null | Pos of node ref
and node = {mutable key : tKey;
mutable left : tBST;
mutable right : tBST};;
내 패턴 매칭처럼 보이는이 기능에 다음과 같은 오류를 데 잘되지 않습니다 데이터 형식이
let rec string_of_tree = function
Null -> "()"
| Pos (ref {key; left = Null; right = Null}) -> Printf.sprintf "(%s)" (string_of_root (root tree))
| Pos (ref {key; left; right}) -> Printf.sprintf "(%s %s %s)"
(string_of_root (root tree))
(string_of_tree (leftLeaf tree))
(string_of_tree (rightLeaf tree));;
Error: Syntax error: ')' expected
Error: This '(' might be unmatched
오류는 다음과 같은 괄호를 말한다 : (REF {키 (...)})
당신이 첫 번째 만'Null' WIH 거래 있도록 아마 두에 일치 식을 분할한다 'Pos' 태그에서 작동하고, 두 번째 것은'ref' 전체를 매칭하는 것이 아니라'Pos' 태그에서 * 참조 된 값 *에서 작동합니다. – didierc