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

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


El 18/06/15 a les 17:05, Ziv Scully ha escrit:
> 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.
>

Ok. with a little bit of debug.

Being

fun null [t] (li: list t) =
    case li of
      [] => True
      | _ => False

(* --- without hamlet --- *)

fun mymodule items = <xml>

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


(* --- with hamlet like style --- *)

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>





More information about the Ur mailing list