-# 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 >>>;
+```