Algebraic Data Types in D?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 09:23:00 PDT 2014


On 7/31/14, 6:03 AM, w0rp wrote:
> On Thursday, 31 July 2014 at 11:42:21 UTC, Remo wrote:
>> http://tech.esper.com/2014/07/30/algebraic-data-types/
>>
>> D already has product type it is struct.
>> But D lacks sum type also called tagged-union.
>>
>> Do you think it would be possible to add something like this to D2 ?
>
> There is a library solution for this in the standard library.
>
> http://dlang.org/phobos/std_variant.html#.Algebraic
>
> It doesn't handle recursive types at the moment, like alias Foo =
> Algebraic!(Foo[]). Apart from that, it should be what you are looking for.

alias Foo = Algebraic!(This[]);

Andrei


More information about the Digitalmars-d mailing list