Hacker News new | past | comments | ask | show | jobs | submit login

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.

      case Rectangle r
        return r.With*r.Height;
      case Circle c
        return pi*c.Radius*c.Radius;

I'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.

That's very neat, it should be pretty easy to sugar something like that into the compiler with no CLR changes.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact