On Thursday, 18 February 2021 at 14:43:43 UTC, Paul Backus wrote:
On Thursday, 18 February 2021 at 14:26:37 UTC, vitamin wrote:
Or combination of discriminate uninons and classes:
/+dub.sdl:
dependency "sumtype" version="~>0.10.0"
+/
import std.stdio;
import sumtype;
alias Expression = SumType!(
ExprValue,
ExprBinary,
ExprUnary
);
class Expr{
abstract Expression expression()pure nothrow @safe @nogc;
}
I don't see what this buys you compared to sticking with one or
the other, but you are correct that it is technically possible.
It infer function atributes (pure, nothrow @nogc @safe) for
"visitor" and let you use classes and inheritence.
With standard visitor pattern you need PureVisitor.
NothrowVisitor, PureNothrowVisitor...