[rust-dev] Functional record update syntax - with different types

Daniel Patterson lists.rust at dbp.mm.st
Mon Aug 6 13:49:21 PDT 2012

The current syntax for record updates:

    struct A {
      a : int;
      b : int;

    let some_a = A { a : 10, b : 10 };
    let other_a = A { a : 0 with some_a };

Sort of hints at being able to combine records of different types; because if the type of other_a is guaranteed by the type of some_a, then the leading A seems redundant. I'm not sure if this is actually desired behavior, but it seems like the following should work:

    struct B {
      a : int;
      b : int;
      c : int;
    let some_b = B { c : 10 with some_a };

Where B would have to contain all the fields of A. Or perhaps A would just have to have all of the fields in B not specified in the record. 

I know that there has been talk about dropping structural records in favor of exclusively nominal ones (or perhaps this has already happened?). In a world of only nominal records, I'm not sure if this is actually desired behavior, and would actually think that not allowing this  and using an alternate syntax for record updates (similar to how Haskell does this) would be better:

    let other_a2 = some_a { a : 0 };

But with structural records, the mixing seems to make sense (and you could even see A { with some_b } as a way to drop the extra fields…).


More information about the Rust-dev mailing list