A proposal: Sumtypes
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sat Feb 17 02:46:26 UTC 2024
On 17/02/2024 3:34 AM, Dukc wrote:
> Thanks for the writeup. I read both DIPs. Honestly, both of them need
> improvement IMO. At present state, I prefer Walter's DIP, mainly because
> the details there are better nailed down.
Mine isn't nailed down, because it isn't worth the effort if Walter
won't even reply to this thread ;)
> By saying that a sumtype is always implicitly convertible to another
sumtype that can structurally hold the same values, you're making it the
tuple of sumtypes. If the user wants to protect the details, he must put
it inside a struct or an union.
What I tried to do was to make it a set. Some places you want a set to
merge, some you don't.
```d
sumtype S1 = int;
sumtype S2 = int | float;
S1 s1 = 1;
S2 s2 = s1;
```
That to me makes sense, both sets contain int, it'll be a common
operation that people will want to do.
So the question I have is why would this not be appropriate behavior,
and instead should error?
More importantly, if you did want to do it, how do you do it without
doing a match, then assign the value? Especially when all the compiler
would need to do is codegen a blit (or with copy constructor call if
provided).
More information about the Digitalmars-d
mailing list