Closed soc closed 2 years ago
Compared to now, "being a enum value" needs to be thought differently, as types defined elsewhere may now be enum values, i. e.:
enum Foo { Bar(...) }; // Bar defined elsewhere
let someBar = Bar(...);
someBar is Foo; // should be true
Here is the idea; consider an enum (ADT) definition like this:
Now, instead of
A
andB
being definition of variants on their own, they refer to existing types instead.This means that one needs to provide an actual (class/struct/module) definition of
A
andB
, which has multiple benefit (and no drawbacks from what I see):Example for 1., 2., 3.
So while ...
... would receive little benefit from being written as ...
... even trivial ADTs like a JSON tree would benefit. Instead of ...
... one would write (with
Array
,Float64
andString
being existing types in the language):Another example would be
ConstPoolEntry
:Example for 4.
It would also do away with having to wrap data into the enum's "variant" when passing arguments, as it's done with the "traditional" approach:
Whether it is desirable to support this for arbitrarily nested enums remains to be seen.
Example for 5.
Consider a class like
With this approach we can use this
Name
type multiple times in different enums (and elsewhere):So from my perspective, this approach reduces indirection at use-site and increases the utility of enums compared to more "traditional" enums, while not changing their runtime costs or representation.