std.sumtype?
Paul Backus
snarwin at gmail.com
Thu Mar 25 15:05:40 UTC 2021
On Thursday, 25 March 2021 at 14:28:06 UTC, Atila Neves wrote:
> If one wants to do that sort of thing, yes, this is nicer. I'm
> still at a loss as to why one would *want* to do such a thing.
>
> I think it's useful to remember that in languages where sum
> types and pattern matching are features there's no way to do
> this.
I suspect the big reason is that a lot of D programmers aren't
super familiar with these languages, or with functional
programming in general, so they find SumType's match function
less comfortable and approachable than switching on an enum (even
though it's fundamentally the same thing).
There's a great illustration of this in a forum thread from last
year [1]. Once I showed how to convert the code to use SumType
and match [2], the author could understand it, but they weren't
able to come up with it on their own.
[1]
https://forum.dlang.org/post/kjozzeynentyrarssnzz@forum.dlang.org
[2]
https://forum.dlang.org/post/bzueywubiazbkxvqnaid@forum.dlang.org
More information about the Digitalmars-d
mailing list