私はこの破壊的な挿入を試みて作成しました:
(* ins:char list *(char trie)ref list->(char trie)ref list *)
fun ins ([], t) = t@[ref Empty]
| ins (x::xs, []) = [ref (Node (x, ins (xs, [])))]
| ins (x::xs, h::tl) =
case !h of
Node (c, lis) =>
if c = x then
(h := Node (c, ins (xs, lis)); h::tl)
else
h::ins (x::xs, tl)
| Empty => h::ins(x::xs, tl)
そして、参照なしで通常の挿入にしようとしていましたが、エラーが発生し続けます。
(* ins: char list * (char trie) list -> (char trie) list *)
fun ins ([], t) = t@Empty
| ins (x::xs, []) = (Node (x, ins (xs, [])))
| ins (x::xs, h::tl) =
case h of
Node (c, lis) =>
if c = x then
(h = Node (c, ins (xs, lis)); h::tl)
else
h::ins (x::xs, tl)
| Empty = h::ins(x::xs, tl)