Sum Types - first draft

Walter Bright newshound2 at digitalmars.com
Tue Sep 10 19:13:33 UTC 2024


On 9/10/2024 10:23 AM, Paul Backus wrote:
>> 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?
> 
> You have it exactly backwards. A _nullable_ pointer type is the sum of a 
> non-nullable pointer type and typeof(null).

"the sum of ..." doesn't make it a sumtype?

> A non-nullable pointer type is a pointer type with its range of valid values 
> restricted. You could think of it as a "difference type"--if you take T*, and 
> _subtract_ typeof(null) from it (i.e., take the set difference [1] of their 
> values), you get a non-nullable pointer type.
> 
> [1] https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement

How is that different from a sumtype?


More information about the dip.development mailing list