Sum Types - first draft

Walter Bright newshound2 at digitalmars.com
Tue Sep 10 17:05:49 UTC 2024


Thanks for your detailed response. Let me address just one for the moment:

On 9/10/2024 9:20 AM, Paul Backus wrote:
>> * std.sumtype cannot optimize the tag out of existence, for example, when having:
>>
>>       enum Option { None, int* Ptr }
> 
> A built-in sum type would not be able to do this either, because in D, every 
> possible sequence of 4 bytes is a potentially-valid int* value.
> 
> The reason Rust is able to perform this optimization is that Rust has 
> non-nullable reference types [2]. If D had non-nullable pointer types, then 
> std.sumtype could perform the same optimization using reflection and `static if`.

I was approaching it from the other way around. Isn't a non-nullable pointer a 
sumtype? Why have both non-nullable types and sumtypes?


More information about the dip.development mailing list