oleg | 9 May 12:55 2014

Templates as typeclasses?


Tobias Dammers wrote:
> You can do similar things with Haskell EDSL-style template systems such
> as Blaze...
>
> Still, the big picture with these is that template building blocks are
> language elements, and template code and regular code can be mixed
> freely. The `h1` function from Blaze is just another Haskell function;
> it takes a MarkdownM () value and returns a MarkdownM (), and because
> MarkdownM happens to be a Monad, you can use do notation to sequence
> HTML elements. MarkdownM () is also an instance of IsString, so if you
> enable -XOverloadedStrings, you can use string literals to produce HTML
> text nodes. This means that you can write, in plain Haskell:
>
>     h1 $ do
>         span "Hello, "
>         span "world!"
>
> ...and it'll produce <h1><span>Hello, </span><span>world!</span></h1>.

In this regard it is worth mentioning HSXML
        http://okmij.org/ftp/Scheme/xml.html#typed-SXML

The document in HSXML is a monoid rather than a monad. It is
hard to find a good reason for the document be a monad except for
using a do notation, which is not needed in HSXML. The above "Hello,
World!" example looks in HSXML as

        h1 (span "Hello") (span "world!")

(Continue reading)


Gmane