A proposal: Sumtypes
IchorDev
zxinsworld at gmail.com
Sun Mar 3 18:34:43 UTC 2024
On Thursday, 8 February 2024 at 15:42:25 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> Yesterday I mentioned that I wasn't very happy with Walter's
> design of sum types, at least as per his write-up in his DIP
> repository.
> I have finally after two years written up an alternative to it,
> that should cover everything you would expect from such a
> language feature.
> There are also a couple of key differences with regards to the
> tag and ABI that will make value type exceptions aka zero cost
> exceptions work fairly fast.
I am pretty pleased with both of these DIPs.
The syntax of the sum types could be tweaked a little:
1. I think that the new keyword should be avoided:
`sumtype` => `enum union`/`case union` (or similar)
2. The `:none` in the sum type's declaration is really odd... it
seems to reference itself from within its own declaration? Why
not just use `void`?
3. Why comma-separation between members? These are a union-like
type, use semicolons.
So, all in all my suggestions would look like this:
```d
case union Nullable(T){
void none;
T value;
}
More information about the Digitalmars-d
mailing list