Do we really need the extra "with Creator" syntax for ADTs? #26
Replies: 1 comment 6 replies
-
It is a possible design. In @rbuckton's version of ADT enum, it works in this way. I design it as two separate things because I have some concerns about this design. If a result of ADT is sent across the ShadowRealm, it will be not matchable by the combined design because the constructor cannot be sent across the ShadowRealm. If we have two separate things, although it's not possible to match by the constructor like this (because ShadowRealm won't clone @@matcher on the constructor when match (value) {
when MessageCreator.Write(message): ...
} But it's still possible to match like this: ( if (value.type === Message.Write) {
...
} |
Beta Was this translation helpful? Give feedback.
-
In the current proposal we have additional syntax for creating a separate factory for instances with the enum being a kind of brand thing. But wouldn't it be simpler if we just had a single name for an enum i.e.
Message
and had the keys as static properties of the functions (or similar) i.e.:Alternatively we might not even need the branding symbol and could just use something like a static method:
Or possibly just using something akin to
.constructor
i.e.:Beta Was this translation helpful? Give feedback.
All reactions