diff options
| author | gingerBill <bill@gingerbill.org> | 2018-09-08 12:02:25 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-09-08 12:02:25 +0100 |
| commit | 3cd6ae311df68c1ac8b4015ebf5eef694126a59b (patch) | |
| tree | 11ef64b5c9187dfd1dfd3ee0d9d268eed84fea45 /examples | |
| parent | 26cfc0257dc891816d6bcdd311a6c348e1d9cdf5 (diff) | |
Parametric polymorphic union type
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demo/demo.odin | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index 2f3e9340e..314475012 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -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); + } } |