It seems to me like we can completely emulate object variants with static enums.
Furthermore, I would guess that it's more memory-efficient since the "kind" is
used at compile-time only.
What are the differences, limitations, tradeoffs between both versions of the
following?
type
NodeKind = enum # the different node types
nkInt, # a leaf with an integer value
nkFloat # a leaf with a float value
# Version 1 with object variant
Node = ref NodeObj
NodeObj = object
case kind: NodeKind # the ``kind`` field is the discriminator
of nkInt: intVal: int
of nkFloat: floatVal: float
# Version 2 with conditional fields
Node2[NK] = ref NodeObj2[NK]
NodeObj2[NK: static[NodeKind]] = object
when NK == nkInt:
intVal: int
elif NK == nkFloat:
floatVal: float