Variant

Tagged multi-schema storage with checked access and reassignment.


Variant

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

Fields

Initialization and destruction helpers

Public methods

Assign, switch tag, and compare

"Variant" use
"String" use
"control" use

{} Int32 {} [
  v0: (Int32 Nat8) Variant;
  v1: (Int32 Nat8) Variant;
  ("tag0=" v0.getTag LF) printList
  7n8 1 @v0.assign
  7n8 1 @v1.assign
  ("tag1=" v0.getTag LF
   "value1=" 1 @v0.get LF
   "equal0=" @v1 @v0.equal LF) printList
  123 0 @v1.assign
  ("tag2=" v1.getTag LF
   "value2=" 0 @v1.get LF
   "equal1=" @v1 @v0.equal LF) printList
  0
] "main" exportFunction

Expected Output

tag0=0
tag1=1
value1=7
equal0=TRUE
tag2=0
value2=123
equal1=FALSE

visit branch dispatch

"Variant" use
"String" use
"control" use

{} Int32 {} [
  v: (Int32 Nat8) Variant;
  7n8 1 @v.assign
  (0 [x:; ("int=" x LF) printList]
   1 [x:; ("nat=" x LF) printList]
   [("default" LF) printList]) @v.visit
  0
] "main" exportFunction

Expected Output

nat=7

Active tag and storage


Access, visit, and reference stability


getHeapUsedSize (variant -- size)

Returns heap usage of the currently active value.


See also