Enumerated Unions (sum types)
Paul Backus
snarwin at gmail.com
Thu Sep 12 10:36:03 UTC 2024
On Thursday, 12 September 2024 at 10:32:39 UTC, Dukc wrote:
> On Thursday, 12 September 2024 at 09:56:44 UTC, Paul Backus
> wrote:
>>> Also I propose that the tag type is enumerated type that is
>>> implicitly convertible to `int`. The base type is an unsigned
>>> integer type big enough to hold all the field types. Default
>>> value and the enumerated values (other than having one for
>>> each type) can remain unspecified though.
>>
>> By "tag type" I assume you mean the type of the __tag
>> property. Is there any practical difference between what you
>> describe and just using size_t?
>
> Well, `size_t` takes more space. Then again, if the tag
> property would be a getter as opposed to a direct field
> accessor the tag type wouldn't necessarily have to match with
> the real type of the tag field, in which case there's no
> difference.
`__tag` is an rvalue property, and the intent is that the
`size_t` it returns can be computed at runtime from the data
stored in the tag field. It's analogous to SumType's `typeIndex`
method.
More information about the dip.ideas
mailing list