let rec add cube v trie = match trie with
| Empty -> List.fold_right (fun a t -> Node [a,t]) cube (Full v)
| Full _ -> trie
| Node l -> match cube with
| [] -> Full v
| atom::cube -> Node (add_to_list atom cube v l)
and add_to_list atom cube v l = match l with
| [] -> [atom, add cube v Empty]
| (atom',t')::n ->
let cmp = Atom.compare atom atom' in
if cmp = 0 then (atom, add cube v t')::n
else if cmp > 0 then (atom',t')::(add_to_list atom cube v n)
else (atom, add cube v Empty)::l