Created
April 13, 2009 01:03
-
-
Save tj/94194 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
--- | |
--- 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