Re: [Haskell-cafe] Generating valid html

I have sent the following message to Haskell-Cafe five days ago; it seems to have disappeared. I'm resending because HSXML answers your second question, of ensuring complex content constraints. I'm not sure why do you need Monad specifically? HSXML documents are particular monoids, which is what we want from documents. Generally speaking, all we need is a way to create primitive documents and to compose them into bigger ones. There are many more composition operations than monadic bind. Not everything is a monad and not everything has to be a monad. Old message: Somewhat related is the HSXML library for generating valid XML and HTML. To be precise, the library is designed to express in the type system content model constraints such as: block-level elements like DIV are allowed only in the block-level context; one cannot put DIV within H1, for example. Some items may be polymorphic: for example, TITLE appears in HEAD, it can be an attribute and it can be an element. It can be rendered differently in each case. The same HSXML document may be rendered as HTML or XML (or something else entirely, e.g., PDF). http://okmij.org/ftp/Scheme/xml.html#typed-SXML

On 19.11.2014 09:46, oleg@okmij.org wrote:
I'm not sure why do you need Monad specifically? Just because of the syntax. If one could have a drop-in layer over Blaze, one might actually use it, simply by changing the import statements.
-- Thank you, Wojtek Narczynski

That's pretty much what my tamper library (http://hackage.haskell.org/package/tamper) is supposed to be. It's pretty rough around the edges still, and nowhere near as complete as Blaze itself, but it works well enough for basic HTML templating, and unlike Blaze, it is implemented as a monad transformer, which means you can integrate it with whatever monad stack you like. I couldn't find an existing solution to this myself, which is why I rolled my own. Having TamperT be a monad transformer is useful for things like passing template context around through a ReaderT, or for reading data from a database on-the-fly by having Tamper transform a monad that provides database access. It's not battle-proven production quality code (yet), so handle with care. On Wed, Nov 19, 2014 at 12:19:24PM +0100, Wojtek Narczyński wrote:
On 19.11.2014 09:46, oleg@okmij.org wrote:
I'm not sure why do you need Monad specifically? Just because of the syntax. If one could have a drop-in layer over Blaze, one might actually use it, simply by changing the import statements.
-- Thank you, Wojtek Narczynski _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Tobias Dammers - tobias@twokings.nl - 070-3457628 - www.twokings.nl Maandag t/m donderdag van 9.00 tot 17.30 Voor dringende vragen, mail naar support@twokings.nl

On 19.11.2014 09:46, oleg@okmij.org wrote:
Somewhat related is the HSXML library for generating valid XML and HTML. To be precise, the library is designed to express in the type system content model constraints such as: block-level elements like DIV are allowed only in the block-level context; one cannot put DIV within H1, for example. Some items may be polymorphic: for example, TITLE appears in HEAD, it can be an attribute and it can be an element. It can be rendered differently in each case. The same HSXML document may be rendered as HTML or XML (or something else entirely, e.g., PDF).
Very nice syntax, but I have yet to figure out how it works. BTW the error messages are "funny", as being discussed right now in another thread. -- Wojtek

Somewhat related is the HSXML library for generating valid XML and HTML. ... http://okmij.org/ftp/Scheme/xml.html#typed-SXML
Very nice syntax, but I have yet to figure out how it works. BTW the error messages are "funny", as being discussed right now in another thread.
Well, HSXML looks just as SXML, only typed. Therefore, many papers and examples that are written about SXML largely apply. I should also point out the example sample1c.hs in the HSXML distribution: test_haskell = (document (head (title "Haskell" longdash "HaskellWiki") (meta_tag (description "All about the language" br "Haskell"))) (body (h1 "Haskell") (div (attr (title "titleline")) (p (a (attr (href (FileURL "/haskellwiki/Image:Haskelllogo.jpg"))) "Haskell" br "A <purely functional> language") br ) (p "Haskell is a general purpose," (em (strong "purely") "functional") "programming language")))) There are a few comments in that file explaining a few difficult parts.
BTW the error messages are "funny", as being discussed right now in another thread.
If we change the document to read ... (p (a (attr (href (FileURL "/haskellwiki/Image:Haskelllogo.jpg"))) "Haskell" (p "A <purely functional> language")) br ) ... we do get a relevant error message No instance for (Build (DC CT_inline d0) (DC CT_block d0) (DC CT_inline d0)) arising from a use of `p' In the third argument of `a', namely `(p "A <purely functional> language")' that says that we are requiring (p ...) to produce CT_inline content (see the flag in the last argument), but p can only produce the block content. Alas, that relevant error message is buried among many irrelevant messages about ambiguous type variables. Things used to be better. The ambiguity check has brought lots and lots of trouble. I could only wish such a feature with many notable consequences were discussed more thoroughly...
participants (3)
-
oleg@okmij.org
-
Tobias Dammers
-
Wojtek Narczyński