[Haskell-cafe] How to print the " character without the backslash

Brian Hulley brianh at metamilk.com
Mon May 29 13:34:01 EDT 2006


Nuno Santos wrote:
> Hi,
>
> I have this basic question of how to print the character " without
> the backslash.
>
> I'm trying to print html code, so i need " a lot.
>
>  giveHtml (Leaf (a,(b,c))) = "<frame src=\"\" name=\"" ++ [a] ++ "\"
> scrolling=\"No\" noresize=\"noresize\" id=\"" ++ [a] ++ "\" title=\""
> ++ [a] ++ "\" />"
>
> Can anybody give me a light here?

One way would be to define a helper function to write an opening tag given 
the tag name and a list of (var,value) pairs:

tag :: String -> [(String,String)] -> String
tag t ps = "<" ++ t ++ " "
    ++ concatMap (\(var, value) -> var ++ "=\"" ++ value ++ "\" ") ps
    ++ ">"

then your code would become escape free:

    giveHtml (Leaf (a,(b,c))) =
           tag "frame"
                 [ ("src", "")
                 , ("name", [a])
                 , ("scrolling", "No")
                 , ("noresize", "noresize")
                 , ("id", [a])
                 , ("title", [a])
                 ]

Regards, Brian.

-- 
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com 



More information about the Haskell-Cafe mailing list