draft proposal for Sum Types for D

Jacob Shtokolov jacob.100205 at gmail.com
Mon Dec 5 17:31:11 UTC 2022


On Monday, 5 December 2022 at 14:50:47 UTC, Paul Backus wrote:
> IMO if you want this kind of extensibility, a sum type is the 
> wrong tool for the job. This is *exactly* the use case that 
> classes are designed for: extending existing code to operate on 
> new types, without modifying the code itself.
>
> Sum types, by contrast, excel when the set of types is fixed, 
> but you would like to be able to define new operations on that 
> set of types without changing existing code.

That would be the case, but D has things like BetterC which 
doesn't support classes (okay, it supports C++ classes, but 
still).

There are other cases where one might need to extend such sum 
types, say, you want to extend error types, etc.


More information about the Digitalmars-d mailing list