D Algebraic Data Types

import std.variant : Algebraic;
import std.stdio : writeln, stdout;
int main() {
	auto v = Algebraic!(int,string)(2);
	stdout.writeln(v);
	int a = *v.peek!(int);
	stdout.writeln(a);
	//stdout.writeln(v.peek!(string)); // is null
	string s = *v.peek!(string); // works but bad idea
	//stdout.writeln(s); // crash
	// compilation error: long b = *v.peek!(long);
	v = "hello";
	return 0;
}

What Algebraic does is implement a very specific sum type, the easiest one, as a class.

I don't know what that kind of overcomplication is supposed to bring but fine, it works.

Currently, Algebraic does not allow recursive data types.

Allegedly, future additions to Algebraic will allow compile-time checking that all possible types are handled by the program.