Skip to content
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

Bug for parsing function clause headers where matched pattern variables are referred in subsequent patterns #626

Open
capfredf opened this issue Feb 19, 2025 · 1 comment

Comments

@capfredf
Copy link
Member

fun
| hello(a , b when a == b):
    println("42")

a in a == b is unbound, but the following code is fine

fun hello(a , b when a == b):
    println("42")
@mflatt
Copy link
Member

mflatt commented Feb 19, 2025

I ran into this recently, too, so I have been thinking about it.

The difference is due to a notion of trying a match versus committing to the match. Without |, there is only one choice, and so you might as well commit to matching arguments as you go. With multiple |s (and, currently, even for just one |), then later arguments may fail to match, in which case matching will move on to the next |, so a call doesn't commit to any match until all are arguments can match. Binding happens after committing, so that's why bindings are unavailable.

In principle, it's a difference between | or not. But my conclusion so far is that this distinction is trying too hard to avoid work, and would be less confusing no worse in practice to commit to matching each argument individually — even if an argument-match result is discarded by moving on to another | clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants