Skip to content

Instantly share code, notes, and snippets.

@chowells79
Forked from ironhouzi/prefixtree.hs
Last active May 6, 2018 15:28
Show Gist options
  • Save chowells79/8208a95fcabc2ac73d1283cdf422fc27 to your computer and use it in GitHub Desktop.
Save chowells79/8208a95fcabc2ac73d1283cdf422fc27 to your computer and use it in GitHub Desktop.
data Ptree a = Pnode a [Ptree a] deriving (Eq, Show)
ptLeaf :: Char -> Ptree Char
ptLeaf c = Pnode c []
ptInsert :: String -> Ptree Char -> Ptree Char
pInsert [] tree = tree
ptInsert (c:cs) (Pnode v children) = case children of
[] -> undefined -- the node has no children
(current:rest) | v == c -> undefined -- the node has children, and the first one is what we're looking for
| otherwise -> undefined -- the node has children, but the first one is not what we're looking for
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment