std.sumtype?

Paul Backus snarwin at gmail.com
Sun Aug 29 15:05:57 UTC 2021


On Sunday, 29 August 2021 at 14:45:20 UTC, SealabJaster wrote:
> On Sunday, 29 August 2021 at 14:29:09 UTC, Steven Schveighoffer 
> wrote:
>> ...
>
> What a shame... I've been using std.sumtype recently and I was 
> really hoping something like this would be added in. It feels 
> really clunky otherwise.

If you find the lack of `typeIndex` is leading to clunky code, 
you are probably not taking full advantage of `SumType`'s 
existing capabilities. In particular, `SumType` strongly rewards 
code written in a "functional" style, where different parts of a 
program are coupled together explicitly via function arguments 
and return values rather than implicitly via shared state and 
mutation.

For a concrete example, have a look at

* [Simen Kjærås's imperative-style code using a tagged union.][1]
* [My functional-style version using `SumType`.][2]

If you can give an example of the kind of code you have in mind, 
I would be happy to give more specific advice.

[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