[Ur] Can one declare a type that will restrict allowable string values on tag attributes?
Burton Samograd
burton at samograd.ca
Wed Aug 7 17:44:37 EDT 2013
Hello Ur List,
My exposure to modern FP and type systems has been through reading
LYAHFGG and many web pages over the years, so I thought I would
do some 'learning by doing' by expanding on the Urblog project for practice
to learn some new concepts.
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.
What I would expect to be able to do is to declare something like a
'string enum' type that would check and restrict the allowable values
handled by the Align/Valign attributes so that a type error is given
when a given string is not within the set of valid values.
Is this level of type checking possible in Ur, and if so, could
someone give a brief example that would work with the above <td>
attribute declaration code? I would expect that Valign would be given a
'valign' type declared to restricted it's allowable values to the strings "top",
"middle" and "bottom". Can this checking of string be made case
insensitive?
--
Burton Samograd
More information about the Ur
mailing list