Created
January 22, 2011 22:27
-
-
Save apk/791563 to your computer and use it in GitHub Desktop.
Simple trial for html repr in haskell
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
-- Simple trial for html repr in haskell | |
data Html = Tag String [String] [Html] | |
| Text String | |
res :: [Html] | |
res = [(Tag "div" [] | |
[ | |
(Text "Hallo"), | |
(Tag "b" [] [Text "Bold"]) | |
] | |
)] | |
instance Show (Html) where show = stringifyItem | |
stringify :: [Html] -> String | |
stringify (h:hs) = (stringifyItem h) ++ (stringify hs) | |
stringify [] = "" | |
stringifyItem :: Html -> String | |
stringifyItem (Tag name attr body) = "<" ++ name ++ ">" ++ (stringify body) ++ "</" ++ name ++ ">" | |
stringifyItem (Text t) = t | |
main ::IO () | |
main = do putStrLn $ stringify res | |
putStrLn $ show res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment