On Sunday, 29 October 2023 at 10:44:03 UTC, ryuukk_ wrote:
If D had tagged union and pattern matching, it would be a great
candidate to succeed in that field
Well, we sort of have it, just not as good as it can be.
https://dlang.org/phobos/std_sumtype.html
The default example though makes it look like it works only with
SumType, here is another example from godot-d where match
compares on types.
``` d
static Variant from(T : GodotType)(T t) {
import std.sumtype : match;
Variant ret;
t.match!(
(Variant.Type t) { ret = cast(int) t; },
(BuiltInClass c) { ret = c.name; },
(Ref!Script s) { ret = s; }
);
return ret;
}
```
Of course there is also third-party libraries that claims to be
"doing it right".