Skip to content

Instantly share code, notes, and snippets.

@apk
Created January 22, 2011 22:27
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 apk/791563 to your computer and use it in GitHub Desktop.
Save apk/791563 to your computer and use it in GitHub Desktop.
Simple trial for html repr in haskell
-- 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