A proposal: Sumtypes

Paul Backus snarwin at gmail.com
Thu Feb 8 17:28:32 UTC 2024


On Thursday, 8 February 2024 at 15:42:25 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> Yesterday I mentioned that I wasn't very happy with Walter's 
> design of sum types, at least as per his write-up in his DIP 
> repository.
> I have finally after two years written up an alternative to it, 
> that should cover everything you would expect from such a 
> language feature.
> There are also a couple of key differences with regards to the 
> tag and ABI that will make value type exceptions aka zero cost 
> exceptions work fairly fast.
>
> [...]
>
> Latest version: 
> https://gist.github.com/rikkimax/d25c6b2bed8caba008a6967e9e0a7e7c

There are two big-picture issues with this proposal:

1. In addition to sum types, it includes proposals for several 
unrelated new language features, like a "member of operator" and 
implicit construction of function arguments and return values.

2. There are several unusual design decisions that are presented 
without any motivation or rationale. For example:

     - "The tag is a hash of both the fully qualified name of the 
type and the name."
     - Copy constructors and destructors are stored as fields
     - "The default initialization of a sumtype will always prefer 
`:none` if present"
     - "Assigning a value to a sum type, will always prefer the 
currently selected tag"

There's a lot more I could say, but I don't think there's much 
value in giving more detailed feedback until these big structural 
issues are addressed.


More information about the Digitalmars-d mailing list