On Friday, 28 February 2025 at 11:33:50 UTC, Dejan Lekic wrote:
> On Friday, 28 February 2025 at 01:06:01 UTC, Paul Backus wrote:
> I'm currently working on Option!T for Phobos v3, and my plan is for it to use SumType internally.
Yes, you can, but why? What are you gaining from using SumType there? It can hold only one value for God's sake...
I am probably missing something, so please enlighten me.
The short answer is: it deals with edge cases around initialization and destruction.
Current Nullable
is basically doing the same thing (if you read the source, it stores its value in a union
), but it's inventing it from scratch instead of re-using SumType
. This is bad for maintenance: I have personally found, and fixed, bugs in Nullable
, for which the equivalent bug in SumType
had already been fixed multiple releases ago (PR 7581 and PR 7582).
Now, you might say, "who cares about those edge cases; just give me the simple implementation that works most of the time." But that's also how Nullable
started out, and it turns out people cared enough about the edge cases to go in and add support for them. Since we already know that the demand exists, it seems prudent to have v3's Option
support these edge cases from the beginning.