OT: (C#) Type Unions for C#
Quirin Schroll
qs.il.paperinik at gmail.com
Mon Aug 12 10:32:05 UTC 2024
On Tuesday, 6 August 2024 at 19:44:12 UTC, Kapendev wrote:
> On Friday, 2 August 2024 at 10:29:22 UTC, ryuukk_ wrote:
>> Some people over here like to take C# as inspiration for new
>> DIPs
>>
>> Well, tagged union is coming to C#, let's resurrect that old
>> DIP and go submit a PR
>
> Tagged unions in C# seem quite complex. 🤢
> Maybe the OdinLang implementation might be a better
> inspiration: https://odin-lang.org/docs/overview/#unions
It seems Odin has type unions. I actually dislike their approach.
IMO, you have two sane approaches:
* Plus-like type sums where order doesn’t matter, duplication
doesn’t matter and they auto-inline. The empty plus-like sum is
`noreturn` and adding `noreturn` to a plus-like doesn’t actually
add it, so that `S+(T+noreturn)` is another way to spell `T+S`.
* Tag-based type unions where order matters, duplication matters
(different tags), they do not auto-inline, and the empty one is
at definition site its own type.
From a plus-based type sum, you extract values asking for a value
of some type. From a tag-based one, you request by tag.
More information about the Digitalmars-d
mailing list