[Ur] Hamlet like XML, structured by indentation with tag autoclosing
Adam Chlipala
adamc at csail.mit.edu
Thu Jun 18 12:18:40 EDT 2015
Here's how I'd write that example in Ur/Web. I don't see an obvious
difference in pleasantness vs. the Hamlet style.
fun mymodule (items : list string) : xbody = <xml>
<h3>title</h3>
<div>
{case items of
[] => <xml><p>Sorry, no items left</p></xml>
| _ => <xml><ul>{List.mapX (fn item =>
<xml><li><b>{[item]}</b></li></xml>) items}</ul></xml>}
</div>
</xml>
On 06/18/2015 09:54 AM, Gabriel Riba wrote:
> Correction:
>
> his indented xml has been designed as a template system for the yesod
> web framework (http://www.yesodweb.com/).
>
> Lets make a comparison with equivalent code:
>
> (* --- hamlet style template *)
>
> fun mymodule items = <ixml>
> <h3> title
> <div>
> $if {null items}
> <p> Sorry, no items left
> $else
> <ul>
> $forall {item} <- {items}
> <li> <b>{[item]}</b>
> </ixml>
>
> (* ---------- without hamlet ---- *)
>
> val emptyListSnippet = <xml>
> <p> Sorry, no items left</p>
> </xml>
>
> fun listItemSnippet item = <xml>
> <li> <b>{[item]}</b> </li>
> </xml>
>
> fun listSnippet items =
> List.foldr join <xml/> <|
> List.map listItemSnippet items
>
> fun mymodule items =
> <xml>
> <h3>title</h3>
> <div> { if null
> then emptyListSnippet
> else <xml>
> <ul>
> {listSnippet items}
> </ul>
> </xml>
> }
> </div>
> </xml>
More information about the Ur
mailing list