First Draft: Nominal Sum Types via `enum union` and `switch` Expressions
Kapendev
alexandroskapretsos at gmail.com
Sat Oct 24 07:59:13 UTC 2026
On Monday, 14 September 2026 at 06:35:13 UTC, Meta wrote:
> ```d
> enum union NetworkPacket
> {
> case Data(const(ubyte)[]),
> case Ping(ulong),
> case Reset(ushort),
> case Heartbeat(),
> case EndOfStream(),
> }
> ```
> ```d
> enum union ConfigValue
> {
> bool,
> long,
> double,
> string,
> string[],
> }
> ```
Looks pretty good!
I didn't know how to feel about the commas, but they make sense
if you are going to define structs inside the enum union. The
main reasons I see making this part of the language is the first
example above, the switch syntax, and it's a type that you often
see in projects (like slices).
This DIP also tries to make a lot of different people happy. For
example, I usually use sumtypes like the second enum union.
Someone that is more familiar with languages like Rust probably
prefers the first enum union. Both options exists and everyone
has what they want.
More information about the dip.development
mailing list