[Haskell-cafe] It's not a monad - what is it? looking for nice
syntactic sugar, customizable do notation?
gale at sefer.org
Tue Sep 2 09:25:56 EDT 2008
Marc Weber wrote:
> (3) Third idea:
> xmlWithInnerIO <- execXmlT $ do
> xmlns "http://www.w3.org/1999/xhtml" >> lang "en-US" >> xml:lang "en-US"
> head $ title $ text "minimal"
> body $ do
> args <- lift $ getArgs
> h1 $ text "minimal"
> div $ text $ "args passed to this program: " ++ (show args)
> I still think that (3) would be superiour..
> Is there a way to define my own >>= and >> functions such as:
There is also the combinator approach of Text.Html, which
gives you a syntax similar to (3) but without abusing "do":
(rootElt ! [xmlns "http://www.w3.org/1999/xhtml",
lang "en-US" >> xml:lang "en-US"]) $ concatXml
[head $ title $ text "minimal"
,body $ concatXml
[h1 $ text "minimal"
,div $ text $ "args passed to this program: " ++ (show args)
You use concatXml (it's concatHtml in the library) followed
by a list, instead of do, for nesting.
(Also, it's stringToHtml instead of text in the library.)
A few more brackets, but still pretty clean. Also, you'll have
pass in your args from somewhere else, in the IO monad -
which is probably a better design anyway.
More information about the Haskell-Cafe