bettersum (v0.7.0): mixin-based sumtypes
Paul Backus
snarwin at gmail.com
Wed Oct 7 15:51:19 UTC 2026
On Wednesday, 7 October 2026 at 02:24:40 UTC, DanielG wrote:
> Dub package:
> https://code.dlang.org/packages/bettersum
>
> GitHub repo:
> https://github.com/dewf/bettersum
>
> Check the README for usage.
>
> I realized a few weeks back that I could probably get 90% of
> what I want (minus legit pattern-matching) from sumtypes just
> by writing a mixin. So, here we are.
Perhaps now you can see why I decided to go with the "type union"
approach for `std.sumtype`, instead of "real" ML-style sum types.
:)
Just from looking at the example in the README, I can see several
unpleasant UX sacrifices you've had to make to get this to work.
In particular, the requirements to (1) manually specify the
return type of `match`, and (2) write all of the cases in exactly
the right order, would be deal-breakers for me, and, I suspect,
for most D programmers.
The conclusion I came to, when I looked at this problem space
8-ish years ago, was that any attempt to implement "real" sum
types in D using only library code would inevitably run into UX
issues like this. In particular, the more compile-time parsing
and code generation you use to work around other issues, the
worse your error messages get, and the slower your code compiles.
There is no free lunch to be had.
More information about the Digitalmars-d-announce
mailing list