Skip to content

Instantly share code, notes, and snippets.

@bavardage
Created September 1, 2010 14:36
Show Gist options
  • Save bavardage/560764 to your computer and use it in GitHub Desktop.
Save bavardage/560764 to your computer and use it in GitHub Desktop.
data Tree = Tree [Tree] | Node Char deriving Show
a :: String -> (Tree, String)
a xs = (Tree ns, rem)
where
(ns, rem) = b xs
-- OMG WHUT HAPPENED HERE
(.:.) :: Tree -> ([Tree], String) -> ([Tree], String)
t .:. (ts,s) = (t:ts, s)
(.|.) :: (Tree, String) -> (String -> ([Tree], String)) -> ([Tree], String)
(t,s) .|. f = t .:. f s
b :: String -> ([Tree], String)
b [] = ([], "")
b xxs@(x:xs) | x == '(' = a xs .|. b --undefined --t .:. (a xs)
| x == ')' = ([], xs)
| otherwise = Node x .:. (b xs)
test = b "df(fg)(f)dffdf()" --this at least works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment