From: Jérémie Astor Date: Mon, 18 Apr 2022 16:44:37 +0000 (+0200) Subject: Improve union docs X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=876b75a6aa25088f7c98422c8764beb53981c262;p=gwion.git Improve union docs --- diff --git a/docs/Reference/Types/Unions.mdr b/docs/Reference/Types/Unions.mdr index 9c39ad55..e5447641 100644 --- a/docs/Reference/Types/Unions.mdr +++ b/docs/Reference/Types/Unions.mdr @@ -1,13 +1,24 @@ -# Union types +# Tagged Union -Union store their component in the same memory space. -For more infomations, see [here](https://en.wikipedia.org/wiki/Union_type). +Union store their component in the same memory space, +but only one element can be used at a time ```gwion,editable union U { - int a; + int i; float f; Object o; }; -``` +#! create an union with field `i` set to `1` +new U(i, 1) => var U u; + +<<< u.i >>>; + +#! set field f to 2.4 +2.4 => u.f; +<<< u.f >>>; + +#! this will trigger an invalid access error +<<< u.i >>>; +```