Parametric polymorphic union type

This commit is contained in:
gingerBill
2018-09-08 12:02:25 +01:00
parent 26cfc0257d
commit 3cd6ae311d
9 changed files with 317 additions and 58 deletions

View File

@@ -471,6 +471,24 @@ parametric_polymorphism :: proc() {
// and let the user specify the hashing function or make the user store
// the hashing procedure with the table
}
{ // Parametric polymorphic union
Error :: enum {
Foo0,
Foo1,
Foo2,
Foo3,
}
Para_Union :: union(T: typeid) {T, Error};
r: Para_Union(int);
fmt.println(typeid_of(type_of(r)));
fmt.println(r);
r = 123;
fmt.println(r);
r = Error.Foo0;
fmt.println(r);
}
}