draft proposal for Sum Types for D
Paolo Invernizzi
paolo.invernizzi at gmail.com
Wed Nov 30 15:04:02 UTC 2022
On Wednesday, 30 November 2022 at 09:33:54 UTC, Walter Bright
wrote:
> On 11/29/2022 12:37 PM, Per Nordlöw wrote:
>> ```d
>> sumtype Result
>> {
>> Error,
>> int Value
>> }
>> ```
>>
>> , is
>>
>> ```d
>> Result res;
>> res = 25;
>> ```
>>
>> supposed to be supported aswell?
>
> At the moment, no, should be:
>
> res.Value = 25;
>
>
>> If so, why not
>
> I'd reframe that as why do it?
>
> On a pragmatic note, there may be multiple matches for an int
> in the sumtype.
I would have preferred a sumtype more similar to a functional
language custom type (like in 'Elm'), where every member must be
of a different type, just to allow what Per was asking.
/Paolo
More information about the Digitalmars-d
mailing list