Skip to content

Instantly share code, notes, and snippets.

@ironhouzi
Created May 7, 2018 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironhouzi/99ba6714f732cef50bb07aa0152377b7 to your computer and use it in GitHub Desktop.
Save ironhouzi/99ba6714f732cef50bb07aa0152377b7 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 [] tree = tree
ptInsert (c:cs) (Pnode v children) = case children of
[] -> ptInsert cs (Pnode v ((ptLeaf c) : children))
(h:t) | h == (ptLeaf c) -> ptInsert cs h
| otherwise -> ptInsert (c:cs) (Pnode v t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment