Skip to content

Instantly share code, notes, and snippets.

@ironhouzi
Created May 6, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ironhouzi/ceb6b49624de6186775e96e8e7a780e7 to your computer and use it in GitHub Desktop.
Save ironhouzi/ceb6b49624de6186775e96e8e7a780e7 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
ptInsert (c:cs) (Pnode v children)
| cs == [] = ptAdd (ptLeaf c) (Pnode v children)
| ptLeaf c `elem` children = ptInsert cs (filter (\n -> n == (ptLeaf c)) children)
| otherwise = Pnode v ((ptLeaf c) : children)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment