On 12/27/2013 02:49 AM, bearophile wrote:
In almost-theory D should allow code like:
import std.stdio, std.typecons, std.variant;
alias Term = Algebraic!(string, Tuple!(string, This[]));
void main() {
const expr = Term(tuple("f", [Term(tuple("g", ["x".Term,
"y".Term])), Term(tuple("a", [])), "x".Term]));
}
In practice std.variant module needs a This defined as "struct This {}",
plus another improvement to support recursive types better, so that code
doesn't work.
That code also can't work because the second type of the "tuple("a",
[])" literal is void[], so it's not compatible.
I am not sure a good enough library-defined Algebraic type can be defined.
mixin ADT!q{ Term: Var char | Op char Term[] };
void main(){
const expr = Op('f', [Op('g',[Var('x'), Var('y')]), Op('a',[]),
Var('x')]);
}