draft proposal for Sum Types for D

JN 666total at wp.pl
Fri Dec 2 20:33:45 UTC 2022


On Tuesday, 29 November 2022 at 06:26:20 UTC, Walter Bright wrote:
> Go ahead, Make My Day! Destroy!
>
> https://github.com/WalterBright/DIPs/blob/sumtypes/DIPs/1NNN-(wgb).md

Looks nice.

Don't like the question mark syntax though. It's going to be 
confusing especially when ternary operator comes into play and 
I'd constantly double-check myself whether ?x.allow is (?x).allow 
or ?(x.allow), even though the first one wouldn't make sense. Why 
not use "is" which is already a keyword?

instead of:

y = ?x.allow ? x.allow : Xyzzy.busy

we'd have:

y = x is allow ? x.allow : Xyzzy.busy

which is more readable naturally and doesn't cause confusion when 
we ever add nullable types with ?. etc.

Regarding the sumtype Option(T) = None | Some(T); syntax... I 
personally don't care much either way, but I feel the original 
syntax fits D better. Things like | for sumtypes or usingn -> for 
return type is something I associate with functional languages 
which feel more math-like in general, but in C-like languages I 
am more expecting of "traditional" syntax. But like I said, I 
don't really care either way, whichever is easier to parse and 
will confuse tools less.


More information about the Digitalmars-d mailing list