A trie:
type lex_node = Letter of char * bool * lex_tree
and lex_tree = lex_node list;;
A function to test whether a word belongs in the dictionary (answer to an exercise from the book “Deploying Applications With Objective Caml”):
let exists word trie =
let rec exists_aux acc nl =
let exists_inner = function
Letter(c,b,nl) -> let wc = (acc ^ (String.make 1 c))
in if b && (wc=word) then true
else exists_aux wc nl
in List.exists exists_inner nl
in exists_aux "" trie;;
Now working on “insert”.