draft proposal for Sum Types for D

Max Samukha maxsamukha at gmail.com
Tue Nov 29 08:52:02 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

I guess 'void' will continue to be an abominable special case?

```
sumtype Result(T)
{
     error;
     result(T);
}

Result(T) bar(alias foo)()
{
     alias R = Result!(typeof(foo()));
     return whatever ? R.result(foo()) : R.error;
}

int baz() { return 0; }
void qux() {}

bar!baz(); // fine
bar!qux(); // no way?
```



More information about the Digitalmars-d mailing list