-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat!: migrate schema to core #273
Conversation
* Schema for the {@link Variant} types, which is a special kind of union type | ||
* where every choice is a struct with a single field denoting the choice. | ||
* | ||
* The `_` branch is a special case which can be used to represent all other |
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.
Is there a reason we have to have the _
special case, instead of specifying this default behavior as a whole other parameter not inside VariantChoices
?
One downside is it seems to preclude using _
as a variant name (not a huge loss, but seems worth avoiding if possible). Is there an upside to specifying the default behavior via a reserved key name?
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.
It is very common in typed languages with pattern matching to use _
as a "default" branch e.g. rust does this, elm does this haskell does this, even ucan invocation spec does it in some sense, so it seemed reasonable to do it here.
One downside is it seems to preclude using _ as a variant name (not a huge loss, but seems worth avoiding if possible).
I think using _
as branch name is bad enough idea that I don't actually feel it's a real loss.
specifying this default behavior as a whole other parameter not inside
VariantChoices
It is possible and I have tried that in fact, but it made inference types and variant
function a lot more complicated and brittle because you ended up with this unnamed branch. In the end it felt clunky so I've chose to go with _
instead.
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.
but it made inference types and variant function a lot more complicated and brittle
I was guessing maybe this was why (but wanted to confirm), and +1 for avoiding the brittleness.
I didn't realize that _
is common in other languages. Thanks for explaining that.
Overview