[Ur] An Ur/Web implementation of TodoMVC

Timothy Beyer beyert at fastmail.net
Tue Jun 17 22:38:58 EDT 2014


At Tue, 17 Jun 2014 16:11:05 -0400,
Adam Chlipala wrote:
>     Keeping functions short and testable?
> 
> I don't generally think of this criterion as too important in languages with expressive static type
> systems.  I don't do systematic testing, and I feel like most such testing in Ruby, etc. is just
> finding type errors!  (Keep in mind that type systems can capture much stronger properties than in
> mainstream languages, such as Ur/Web's use of types to catch bad links, schema-incorrect database
> accesses, the equivalents of "wrong ID errors" in imperative JavaScript code, etc.)
> 

Just a random thought, could function level pattern matching be a possible
improvement in future versions of Ur/Web? Is there a reason why it can't be
implemented (type system, semantics, or otherwise)? I wasn't able to get that
feature working in any of my own code, relative to Standard ML pattern matching
examples.

Using the function mapX as an example:

fun mapX [a] (f : (unit -> list a) -> a -> xbody) (ls : list a) : xbody =
    let
        fun mapX' ls acc =
            case ls of
                [] => <xml/>
              | x :: ls => <xml>{f (fn () => List.revAppend acc ls) x}{mapX' ls (x :: acc)}</xml>
    in
        mapX' ls []
    end

I'd rather write something like the following (assuming that arguments are
treated as a tuple of values):

fun mapX [a] (f : (unit -> list a) -> a -> xbody) (ls : list a) : xbody =
    let
        fun mapX' (ls, acc) =
          ([], _) => <xml/>
        | (x :: ls, _) => <xml>{f (fn () => List.revAppend acc ls) x}{mapX' (ls, (x :: acc))}</xml>
    in
        mapX' (ls, [])
    end

Is something like this already possible in Ur/Web? I know it is just syntax,
but I have a lot of code that would be much prettier with fewer direct case
statements.  A requirement to write case statements directly at the top of
function bodies to get pattern matching makes code harder to read, and it
appears less declarative to have code littered with so many keywords, even
though it's otherwise equivalent.

If implementing such a feature isn't contrary to the goals of Ur/Web, and isn't
too difficult, I wouldn't mind submitting patches, although I haven't looked at
the compiler source in a while.

Regards,
Tim



More information about the Ur mailing list