3 ms·
I still lack some kind of sum type that is always checked for exhaustiveness. When I'm creating a class hierarchy for a domain, 9 times out of 10 I'd rather hav
by alkonaut 10y ago
I still lack some kind of sum type that is always checked for exhaustiveness. When I'm creating a class hierarchy for a domain, 9 times out of 10 I'd rather have a simple sum type. When I have to make a class hierarchy in C# anyway (because there are no simple sum types). I'd like to be able to write something like this, and have this match/switch fail to compile if I add a new type of shape.
match(shape)
{
case Rectangle r
return r.With*r.Height;
case Circle c
return pi*c.Radius*c.Radius;
}
- macca321 10y agoI'm just going to pimp my library (github.com/mcintyre321/OneOf) which lets you pull this off in c#. I'm quite sad it's needed though, it would be great to have it in the language.
- alkonaut 10y agoThat's very neat, it should be pretty easy to sugar something like that into the compiler with no CLR changes.