First Draft: Nominal Sum Types via `enum union` and `switch` Expressions

Dennis dkorpel at gmail.com
Tue Sep 15 17:00:14 UTC 2026


On Tuesday, 15 September 2026 at 15:30:14 UTC, Meta wrote:
> Compile times and error messages aren't the main reason I think 
> language-level sum types are useful, (...)
> 
> [Layout optimization is] not core rationale. I think the DIP 
> stands on its own without that section.

If not for for those 2 items, what is the rationale for adding 
specifically all the described machinery to the language? I don't 
see anything else in the rationale section.

> But the error messages are significantly better and more 
> accurate by simple virtue of the fact that the compiler has 
> access to a lot of information that user code doesn't.

Such as?

> Also doing pretty much anything with a library-based sumtype 
> involves a *ton* of template instantiations. You don't need 
> hard numbers to conclude that a language-level implementation 
> will significantly improve on compile times, memory usage, 
> symbol bloat, the optimization the compiler can perform, etc.

I understand the real world correlation between template usage 
and slow compile times is a thing, but I find "library therefore 
templates, templates therefore slow" a bit weak for such a big 
DIP. The DIP doesn't dictate anything about the language 
implementation either. What if it gets implemented by lowering to 
templates in druntime (like Associative Arrays are now)?

> It's technically true that a library sumtype could do this type 
> of optimization (although there are still some things the 
> compiler can do that are impossible for a library type)

Such as?

> but it's difficult, tedious, and to my knowledge no library 
> solution in D has actually done it.

Why would it be easier in the compiler?

Btw I'm not speaking as a stickler for std.sumtype who doesn't 
see the appeal in a language solution. However, I do find the DIP 
in its current state very lopsided, focused on the "what" and not 
"why", making it easily rejected in formal assessment. I know the 
judges are Walter and Atila now, not Walter and Andrei 
Alexandrescu, but his ideas on DIPs and language  vs library 
features still resonate with me.

"A good DIP creates a scientific argument. It would have the 
general attitude of building, through a series of factual 
statements, a hypothesis that is convincing. A neutral person 
with the proper background would read the facts and reach the 
conclusion as much as the author."

"The most important principle in a language design is to define a 
small core of essential primitives. All necessary syntactic sugar 
lowers to core constructs. Do everything else in libraries."

"An in-language solution doesn't only mean no addition is needed, 
but more importantly it means that the language has sufficient 
power to offer D coders means to solve that and many other 
problems."

"[the library solution] exposed a number of important, 
power-limiting bugs in the D language and its compiler (that have 
since been fixed to great effect), and it provided a model for 
future work based on introspection and code generation. That 
ended up pretty much defining the direction of the entire D 
language, and is the most compelling differentiating feature of D 
from other languages."




More information about the dip.development mailing list