Union

Tagless overlapping storage for one value chosen from a fixed list of schemas.


Union

Construct with a schema list in tuple form, for example (Int32 Nat8) Union.

Fields

Methods

Alignment and size helpers

Getter result schemas

"Union" use
"control" use

{} () {} [
  u: (Int32 Nat8) Union;
  0 @u.get printStack _:;
  1 @u.get printStack _:;
] "main" exportFunction

Expected Output During Compilation

Int32 Ref
Nat8 Ref

Write through typed refs

"Union" use
"String" use
"control" use

{} Int32 {} [
  u: (Int32 Nat8) Union;
  123 0 @u.get set
  ("int=" 0 @u.get new LF) printList
  7n8 1 @u.get set
  ("nat=" 1 @u.get new LF) printList
  0
] "main" exportFunction

Expected Output

int=123
nat=7

Reinterpret the same storage through another key

"Union" use
"String" use
"control" use

{} Int32 {} [
  u: (Int32 Nat32) Union;
  -1 0 @u.get set
  ("asInt=" 0 @u.get new LF
   "asNat=" 1 @u.get new LF) printList
  0
] "main" exportFunction

Expected Output

asInt=-1
asNat=4294967295

Storage and reference semantics


See also