Sum type, the D way
Walter Bright
newshound2 at digitalmars.com
Tue Nov 29 18:58:59 UTC 2022
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.
Another problem is, as you mentioned, the open nature of enums, which won't work
with sumtypes.
Then there's the issue of implicit casting of enums to their basetype. Not sure
sumtypes are implicitly convertible.
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 :-)
More information about the Digitalmars-d
mailing list