-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add quotes.Type.valueOfConstant #11715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add quotes.Type.valueOfConstant #11715
Conversation
With quote pattern matching it is possible to match over the structure of a type, this add to possility to extract the values from constant types. This is esential to provide handle `Mirror.{MirroredLabel, MirroredElemLabels}` witthout needing reflection.
It seems to me using reflection in such cases agrees with the design philosophy of doing complex things in reflection. There are several concerns: (1) adding ad-hoc methods is difficult to learn & remember. |
The design philosophy is to make simple thing easy and safe and complex things possible. The following points go against it.
It is in the same place all other methods on type are located. It is also the simplest part of the whole matching on
Scale how? This is the leaf of the operations that we need, scaling to complex types is already handled by pattern match. The point is to have a safe and simple API. Using reflection is not a principled way to do it unless you redefine this operation in each project that needs it (i.e. every project matching on mirrors).
It is type-safe. |
It seems we are adding more methods that are based on reflection to achieve type-safety --- I'm wondering what is the criteria for doing/not-doing so. This is the concern about scalability in my mind.
Maybe |
Not sure how this could scale. We will probably not be adding more singleton constant type to the language any time soon.
That was a mistake we previously did with the extraction of values out of expression. It made it harder to use and in many cases ended up calling the same extractor several times. The solution was to add |
I think the context is different. For |
Still, we need this if we want people to write type class derivation using macros without them doing horrible workarounds. Without this we would make the complex part simple and the trivial part hard. That isn't a good idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'll leave you to decide whether it's better to be an extractor or not.
With quote pattern matching it is possible to match over the structure of a type, this add to possility to extract the values from constant types.
This is esential to provide handle
Mirror.{MirroredLabel, MirroredElemLabels}
witthout needing reflection.