4 ms·
All I want is easy syntax for immutable records, and C#-like a fluent syntax for .WithPhoneNumber(phoneNumber) etc. Seems like it'd be a cinch to implement, an
by daxfohl 10y ago
All I want is easy syntax for immutable records, and C#-like a fluent syntax for .WithPhoneNumber(phoneNumber) etc. Seems like it'd be a cinch to implement, and for me the single handiest feature from F#.
In F# these are "guaranteed" to be non-null, even though null instances come up during deserialization all the time. In C# use cases, I don't think the non-null "guarantee" should be made or implied, just a POCO.
- CyrusNajmabadi 10y agoHi there! C# language designer here. You can see (and participate in) the discussion on records here if you'd like: https://github.com/dotnet/roslyn/issues/10154 https://github.com/dotnet/roslyn/issues/10154 > Seems like it'd be a cinch to implement Ah... how i wish that were so :)
- daxfohl 10y agoIndeed. While records are my favorite feature from F#, they could be improved. I'd love it if record definitions were extensible (even abstractly--sometimes you want a record with just the data, and sometimes including db-centric "id, createdTime, etc"), and there should be a way of defining / converting between them without a ton of boilerplate. That would allow something like: record DbStuff = { id: int; created: DateTime } record UserRecord: DbStuff { name: string; ... } var userRecord = new UserRecord(...) var userData = userRecord.WithoutDbStuff() // but what would be the reflected name of this type? var newRecord = userData.WithDbStuff(3, DateTime.Now) ---- Sometimes you want to be able to define records PhotoData{source, metadata, yada, etc, url} and PhotoDisp{source, metadata, yada, etc, bytes} without the repetition, and again with an easy way to convert between the two. (And yes you could simplify the above by using containership but oftentimes there are cross-cutting things that containership doesn't solve. You really want a flattening solution.) Easy integration with C# anonymous classes should be considered too. C# has always been the more real-world-centric language so I'd hope these common use cases would be considered.
- JamesBarney 10y agoI second this! The ability to easily create intersection types would be awesome!