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
interop with new pattern matching proposal #225
Comments
it brings an interesting problem. The record and tuple are designed to "transparent" to the user (which means they are both use normal match (#{a: 1}) {
when ({a}) "matches!"
} And what if the dev wants to match objects but not records, or wants to match records but not objects? |
Given that Records and Tuples are primitives, it would use === semantics if we made no changes to account for them. Absolutely i think if the pattern is a record/Tuple, then it should only match on records and tuples. However, this seems to be asking about when the matchable is one, and the pattern is an object/array pattern. Given that object and array destructuring will (presumably) work just fine with Records and Tuples, i think that there is simply no other option than making their patterns match against Records and Tuples. Thus, if you want to match records but not objects, you’d use a guard (which is a totally reasonable escape hatch for any comparison one wants). Either way, whichever proposal advances second is the one that would have to account for this, so it seems like something that can be deferred until they’re both not at the same stage. |
Not quite; we don't have a generic "any primitive" slot in the grammar. The "primitive matchers" are explicitly carved out as patterns (since, in particular, they're actually more than primitives, including some unary-operator expressions and well-known variable names). So the example in the OP would be a syntax error if we did nothing to accommodate it. If they record/tuple was wrapped in I do agree that adding record/tuple patterns makes sense, and we should make sure that the second-mover proposal handles this. |
The spec for pattern matching is far from finalized; I suspect we would, actually, specify it using the same grammar productions that the language uses to parse primitives, with special cases for |
We expect pattern-matching to decide how they will handle Record & Tuple. Our champion group will be happy to review the interaction of pattern matching and Record & Tuple. Since Record & Tuple already destrucuture like Objects & Arrays, we don't expect widely different behaviour here. |
The pattern matching proposal just made a huge progress. it's very useful and well designed on its own, but it would be great to works with tuple and record.
I haven't discovered any compatibility the following code should just work
please consider this integration and moving tuple and record proposal forward
The text was updated successfully, but these errors were encountered: