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
エラーは以下の括弧を参照します(参照{キー;(...)})
:-)最初のものだけ 'NULL' WIH扱うようにあなたはおそらく、二つにあなたの一致式を分割する必要があるでしょう残念ながら
{ contents = ... }
を使用することができます参照照合するために、 'Pos'タグで動作し、' Pos'タグで動作します。 – didierc