draft proposal for Sum Types for D

12345swordy alexanderheistermann at gmail.com
Tue Nov 29 15:10:15 UTC 2022


On Tuesday, 29 November 2022 at 14:51:34 UTC, Timon Gehr wrote:
> On 11/29/22 07:26, Walter Bright wrote:
>> Go ahead, Make My Day! Destroy!
>> 
>> https://github.com/WalterBright/DIPs/blob/sumtypes/DIPs/1NNN-(wgb).md
>
> Another thing to consider:
>
> sumtype A{
>     int a;
>     B b;
> }
>
> sumtype B{
>     int c;
>     int d;
> }
>
> Is the following allowed?
>
> A a;
> ...
> if(?a.b.c){ ... }

More importantly does it support?

sumtype A{
     Null;
     A a;
}

If so, are their any plans for default initialization using the 
GC when it comes to chaining?

I.E.

a.?a.?a

or custom syntax when returning a default value if it said 
sumtype is determined at run time to have a null type?
I.E.

int x = a.a ?? 0;
without having to type
if(?a.a)
{
int x = a.a;
}
else
{
int x = 0;
}
or using the ternary conditional operator for this?

- Alex


More information about the Digitalmars-d mailing list