A proposal: Sumtypes

ryuukk_ ryuukk.dev at gmail.com
Thu Feb 8 18:10:37 UTC 2024


I personally not a fan of having a new keyword, it's words i can 
no longer use in my code, we have `union` and `enum` a sumtype is 
the combination of both, so why not:


```D
union MyTaggedUnion: enum {
     A a,
     B b,
     C c,
}
```

It'd loose your one liner idea however


I am not a fan of using `.match` and not a fun of having `match` 
wich is yet another new keyword, why not reuse `switch`?

It's easy to distinguish with C's switch, just check presence of 
`case`


```D
switch (value) {
     :A => writeln("This is A: ", value);
     :B => writeln("This is B: ", value);
     else => writeln("something else");
}
```

I would also make a proposal for `switch` as expression, wich i 
guess already is possible with your `match` idea?


I like it so far, hopefully things moves fast from now on




More information about the Digitalmars-d mailing list