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

Allow extended pattern-matching for function arguments and let bindings #44

Open
DKLoehr opened this issue Dec 5, 2019 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@DKLoehr
Copy link
Collaborator

DKLoehr commented Dec 5, 2019

Would be nice to write e.g. let trans _ x = x + 1 instead of having to declare an unused variable for the edge. It would also be easier to e.g. unpack tuples automatically.

@alberdingk-thijm
Copy link
Collaborator

This seems like a worthwhile change outside of functions too: if we could make the left-hand side of a let binding be a pattern, instead of an identifier, we could then destruct data into multiple identifiers with one let, e.g.:

let trans e (x1, _) =
  let u~v = e in
  let { a; b; c } = x1 in
  if u = 0n then a + b else a + c

@DKLoehr
Copy link
Collaborator Author

DKLoehr commented May 28, 2021

Yeah, this is a nice QoL feature to have. I think we already allow this in let-statements, it just gets turned into a match statement during parsing. We could possibly implement it for function arguments by creating fresh variable for each argument pattern during parsing, then starting the body with a match to destruct it according to the user's pattern.

@alberdingk-thijm
Copy link
Collaborator

From what I can see, this is only done for tuples in let statements right now. Parsing throws an error for both patterns above. That being said, I would think they would both be implementable using that desugaring approach you describe.

@alberdingk-thijm alberdingk-thijm changed the title Allow pattern-matching for function arguments Allow extended pattern-matching for function arguments and let bindings Jun 10, 2021
alberdingk-thijm added a commit that referenced this issue Jun 10, 2021
Add an example network showcasing different let pattern sugar to
implement in NV. Demonstrates work needed for #44.
alberdingk-thijm added a commit that referenced this issue Jun 13, 2021
Change the parsing rule for let patterns to include all possible
patterns, all of which desugar using a match.
This doesn't appear to break anything right now, although it conceivably
*could*, so proceed with caution.
Partially handles #44: for functions, we'll need to modify the component
and fun expression parsing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants