[web-devel] Uniform substitution for URLs, templates, messages and other expressions in Shakespearean templates

Sebastian Fischer mail at sebfisch.de
Sun Sep 23 11:14:50 CEST 2012


Hello,

when writing my comparison of Hamlet with Heist and HXT
(https://gist.github.com/3757918) I noticed that Hamlet and HXT have
similar approaches to variable substitution but Hamlet's uses
different syntax for substituting URLs, templates, and other
expressions. I'd like to understand why.

In HXT Haskell expressions can be substituted using the notation <%
... %>. The rendering of substituted expression is type based and
specified separately for attribute- and element-positions via type
classes `EmbedAsAttribute` and `EmbedAsChild`.

In Hamlet Haskell expressions can be substituted using the notation
#{...}. The rendering of substituted expressions is type based and
specified via the type class `ToMarkup` from the blaze-html package.
URLs are substituted using the notation @{...}, other templates using
^{...} and messages for i18n using _{...}.

What are the reasons for providing four different syntaxes for
variable subsitution if the substitution is type based? For example,
different escaping mechanisms (URL escaping for routes, HTML escaping
for strings) could already be accomplished with a single syntactical
construct based on different type-class instances to generate markup.

Best,
Sebastian



More information about the web-devel mailing list