[Ur] Can one declare a type that will restrict allowable string values on tag attributes?

Adam Chlipala adamc at csail.mit.edu
Thu Aug 8 14:33:17 EDT 2013


On 08/07/2013 05:44 PM, Burton Samograd wrote:
> During my experimenting, one of the first things I noticed about the
> Ur basis library is that not all XHTML tag attributes are handled by
> the embedded XHTML language. I added the Align and Valign attributes
> to the<tr>  tag like this:
>
>      val td : other ::: {Unit} ->  [other ~ [Body, Tr]] =>  unit
> -      ->  tag ([Colspan = int, Rowspan = int] ++ tableAttrs)
> +     ->  tag ([Align = string, Valign = string , Colspan = int, Rowspan = int] ++ tableAttrs)
>               ([Tr] ++ other) ([Body] ++ other) [] []
>
> This change worked and the tags were generating correctly in the
> output XHTML, but I could see a problem. Align and Valign should
> only take a specific set of strings as parameters ("top", "left", "right",
> etc.) leaving me thinking the 'Align = string' and 'Valign = string' type
> declarations above are lacking.
>    

It would be possible to implement the level of static checking that 
you're proposing, but only by modifying the compiler implementation, I 
think.  Many of the web-specific elements of Ur/Web have associated 
compiler code, though, as an open research problem, I'd love to see a 
more modular compiler design that supports easy repurposing for 
different domains.

The easiest change would be to define in basis.urs an abstract type of, 
e.g., "valign" values.  The real implementation could be [string], and 
you would provide a number of primitive values of this type that in the 
end get implemented with constant strings.  I think this would probably 
require adding a new case in src/monoize.sml for each new member added 
to [Basis].



More information about the Ur mailing list