Record in C# 9 (proposal)

forax at forax at
Sat Dec 7 19:37:46 UTC 2019

----- Mail original -----
> De: "John Rose" <john.r.rose at>
> À: "Brian Goetz" <brian.goetz at>
> Cc: "Remi Forax" <forax at>, "amber-spec-experts" <amber-spec-experts at>
> Envoyé: Samedi 7 Décembre 2019 02:51:59
> Objet: Re: Record in C# 9 (proposal)

> On Dec 6, 2019, at 7:58 AM, Brian Goetz <brian.goetz at> wrote:
>> Yes, we’ve been watching this one for years — they started on this effort
>> shortly before we started on ours.  Obviously they built a different feature
>> because they have a different language; for example, records interact
>> positively with C# properties.
>> Their chosen design persona is much more of a Billy Boilerplate than a Tommy
>> Tuple.
> +1
> They have a clever “with” mechanism.

yes, that's the most interesting part,

>  We might try to do something similar,
> but as link-time sugar, not compile-time, so that an invokedynamic handshakes
> with one or more “with” link points to update zero or more named components.
> IMO the call site linkage should be as complex as the number of read and written
> components, not as complex as the whole record.

not sure to follow ...
given that we need to construct a new Record, so you have to write all the components of the new record anyway.

> It could be implemented as the caller passing in a lambda to the callee, who
> invokes the lambda on the read components and receives back all the written ones
> (multiple value return again!) before returning the updated record instance.
> Whatever multiple value return we do for pattern matching is a candidate
> here also, although the arrows run in reverse, compared to a match.
> Where a “match” pulls out some values from the record, a “with” pushes
> them back in.  There’s more, of course, because a “with” will often update
> a component, as in `__With mycursor __Update x++;` (not the real
> syntax).

For me, we don't need a special method with(), we already have the canonical constructor.
So with can be translated to an indy that will call the canonical constructor with the name of the components as bootstrap argument. In the BSM, the idea is to use permute arguments to insert the with values at the right place and duplicate this at the other places and then calls filters to calls the getters where this has been duplicated. 

This kind of transformation is as complex as the string concatenation. So it's not simple but it's far simpler than the pattern matching.

> — John


More information about the amber-spec-experts mailing list