Skip to content

Instantly share code, notes, and snippets.

@tj
Created April 13, 2009 01:03
Show Gist options
  • Save tj/94194 to your computer and use it in GitHub Desktop.
Save tj/94194 to your computer and use it in GitHub Desktop.
---
--- Tag
---
data Tag = Tag {
tagType :: String,
tagAttrs :: [Attr]
}
data Attr = Attr String String
---
--- tagToHTML
---
tagToHTML :: Tag -> String
tagToHTML t = "<" ++ tagType t ++ " " ++ attrs ++ "/>a"
where attrs = join (map attrPair (tagAttrs t))
---
--- attrPair
---
attrPair :: Attr -> String
attrPair (Attr k v) = k ++ "=\"" ++ v ++ "\""
---
--- join
---
join :: [String] -> String
join (x:xs) = x ++ " " ++ (join xs)
join [] = ""
--- main
input = Tag "input" [Attr "id" "comments", Attr "disabled" "disabled"]
main = print (tagToHTML input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment