Created
September 1, 2010 14:36
-
-
Save bavardage/560764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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