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

Ziv Scully ziv at mit.edu
Thu Jun 18 11:05:53 EDT 2015


A more direct translation is the following, which is a little more clunky
than but has the exact same structure as the original.

fun mymodule items = <xml>
  <h3>title</h3>
  {if null items
   then <p>Sorry, no items left</p>
   else <xml>
      <ul>
       {List.mapX (fn item =>
          <xml><li><b>{[item]}</b><</li></xml>)}
     </ul>
   </xml>}
</xml>

At the moment, the only place to learn about List.mapX and friends is by
looking through the .urs files in lib/ur, though the types of most of the
functions make clear what they do.


On Thursday, June 18, 2015, Gabriel Riba <gabriel at xarxaire.com> 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>
>
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20150618/e7fc6a58/attachment-0001.html>


More information about the Ur mailing list