sumtypes for D
Timon Gehr
timon.gehr at gmx.ch
Wed Nov 30 02:26:14 UTC 2022
On 11/30/22 00:56, Vladimir Panteleev wrote:
> On Monday, 28 November 2022 at 09:27:11 UTC, Walter Bright wrote:
>> I've written most of a DIP for one. Should I:
>
> I really wish that instead of adding more language features, we would
> improve the language so that things like this are implementable *in* the
> language.
Well, ideally both. Tagged unions are fundamental enough to get some
syntactic sugar. So are tuples. But except for syntax, I agree that
user-defined types should be able to benefit as well.
Here, I guess this would mean to add some mechanism to allow the
language to understand which `union` member is currently active. This
would also help with precise GC.
Another consideration is compile times. Sometimes it makes sense to
build things into the language because you don't want to interpret them
again and again if you can compile them once into the compiler frontend.
I also don't like magic though. Ideally it should be possible to write a
shallow wrapper `struct` (template) around any other type without losing
any functionality.
More information about the Digitalmars-d
mailing list