draft proposal for Sum Types for D
deadalnix
deadalnix at gmail.com
Tue Nov 29 15:54:51 UTC 2022
On Tuesday, 29 November 2022 at 06:26:20 UTC, Walter Bright wrote:
> Go ahead, Make My Day! Destroy!
>
> https://github.com/WalterBright/DIPs/blob/sumtypes/DIPs/1NNN-(wgb).md
So I spent the last working on something that effectively boils
down to sum types with a couple of twists. While having this DIP
on hand would like have made part of the work easier, it doesn't
address the main challenges I ran into (one of them is solved,
the other one is still up in the air).
The first problem that needed to be solved is automated
conversion between sum types members. Think if you are trying to
run this operation that exist on A but not on B, and the sum
value currently contains a B, then convert that B to an A and
then run the operation.
The second one is that it ends up replacing builtin types in the
codebase by custom types, most notably dynamic arrays (which I'll
call slices). Doing so de facto breaks most of the codebase in
ways that cannot be easily fixed, because there is no way to have
a builtin type that behave like a slice.
That second problem is the most important one. As of now, it has
occupied roughly half the time I spent on the project as a whole,
and it is still not even close to be solved. I was able to
develop a custom sum type, which includes custom hash table and
clever transform to convert the types into one another, and it's
bonkers that this isn't dominating the dev time I have to spend
on this.
More information about the Digitalmars-d
mailing list