Discriminators as first class citizens of sum types #21205
goshacodes
started this conversation in
Feature Requests
Replies: 1 comment 13 replies
-
The ordinal of an enum case is compile time information - its the index of the type in the MirroredElemTypes in the Mirror - which you can compute manually, or its the same as |
Beta Was this translation helpful? Give feedback.
13 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider following AST:
"bar" and "baz" are literal constants, but now they are not exposed at compile time in any way.
So to make derivation of JsonReader (for example) possible I need to stub all case children instances and get this field.
I propose to:
So generation of this code could be possible without dirty hacks
Why not use ordinal or MirroredElemLabels:
Enum ordinal is bound to ordinal, consider situation when developer changes order of case chilren (just because he doesn't like it) and deserialization starts failing at runtime
When you write integration with other software systems you often use provided by that system protocol, where discriminators can be strings and not bound in any way to ordinal of case children in your scala model
Case labels have same problem, they are bound to your case class name
Beta Was this translation helpful? Give feedback.
All reactions