Sum type, the D way

deadalnix deadalnix at gmail.com
Tue Nov 29 19:40:15 UTC 2022


On Tuesday, 29 November 2022 at 18:58:59 UTC, Walter Bright wrote:
> My original sumtype design was indeed extending the enum. But 
> eventually, trouble surfaced. For example, the pattern matching 
> that goes on with types, such as for IsExpressions, and for 
> template parameters. Suddenly, existing code that is expecting 
> an enum would match a sumtype, likely causing problems.
>

I'm sure this can be sorted out.

> Another problem is, as you mentioned, the open nature of enums, 
> which won't work with sumtypes.
>

It already doesn't work today, with things like final switch. You 
have the power to fix it.

This is exactly why I'm telling you to not roll out sum types 
right now. You are building on top of quick sands.

> Then there's the issue of implicit casting of enums to their 
> basetype. Not sure sumtypes are implicitly convertible.
>

I don't understand what the issue is here.

> So then it just seemed simpler with a lot fewer special cases 
> to make sumtypes a separate entity. One problem that does 
> resolve, is they'll be closed, which I think you'll like :-)

Making the whole thing a special case doesn't typically 
translates into fewer special cases.



More information about the Digitalmars-d mailing list