-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Matching pattern languages #528
Comments
A concern with
and this one, which (until you apply constant folding), needs to behave the same way for the same reasons, which is far from obvious to the casual reader (or even someone like me with his fingers deep in the implementation):
|
I think we don't want "normal" (unguarded) |
Depends if you want overloading == pattern matching or not. If that's what you want, there's nothing wrong in principle with having a refutable overload as long as the whole overload set is irrefutable. I personally wouldn't design pattern matching into overloading in this way—a match statement inside a function body is a much more straightforward way to get the same effect—but this is what I (and others) have understood the design intent to be.
🤷 if you don't care that the same syntax might imply different semantics, none. I don't think the real question is what the syntax should be, but whether we're really trying to uphold the principle that "it's all just pattern matching." If the answer is yes, keeping the syntax the same makes sense. If not, maybe there's more flexibility. |
I don't think we should treat this as a yes-or-no question. It's probably not realistic to insist that any code that's valid in a The main principle that I would like us to try to stick to is that function parameter lists, Most if not all of the problems discussed so far seem like they can be resolved consistently with that principle, e.g. by disallowing refutable patterns in variable declarations and function signatures. Do we have any examples of problems that don't seem to be solvable under that principle? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
What I've heard so far:
|
Some of these questions have been answered by approved proposal #2188. In particular:
I think the remaining question here is, do we have syntactic restrictions on some of these pattern contexts? That is, do we allow only a subset of the pattern grammar, depending on which kind of pattern we're parsing? And if so, what are the restrictions that we impose? We've spun some of that out into separate questions:
I think given the discussion on those issues, we can answer the remaining question as: yes, we may have additional restrictions for some or all pattern contexts, depending on the needs of that context. We'll decide what restrictions make sense for different contexts separately. |
Agreed and calling this decided. |
We have so far been trying to design a single pattern syntax to be used across variable declarations, function declarations, and match statements. This is turning out to be a big constraint, and we have been bumping into the problems with this approach recently. This approach is only common in functional languages with very different needs. I think it is time to ask the question of whether we should treat these as separate problems in order to better address their individual needs.
Lets look at what each context needs:
fn
function declarationfn F(Int)
doesn't match user's expectationsfn F(Int)
problem.var
variable declarationmatch
statementsswitch
and don't need name bindings or typesguard
statementsMy contention is that these are pretty different use cases, each with unique concerns to accommodate.
The text was updated successfully, but these errors were encountered: