[Ur] Hamlet like XML, structured by indentation with tag autoclosing

Gabriel Riba gabriel at xarxaire.com
Thu Jun 18 09:54:54 EDT 2015


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