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

feat(compiler)!: Partial function application #2091

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alex-snezhko
Copy link
Member

Partial function application

let add = (x, y) => x + y
let add1 = partial add(1, _)
assert add1(2) == 3

let printValues = (x, y, z=3) => {
  print(x)
  print(y)
  print(z)
}
let printSome = partial printValues(y=2, _, z=_)
printSome(1) // prints 1, 2, 3

Closes #402

@alex-snezhko
Copy link
Member Author

alex-snezhko commented Apr 8, 2024

TODO:

  • Make precedence of partial tighter to allow x |> partial add(_, y) without parentheses around the partial expression
  • Decide if this feature should be supported for infix functions - doesn't seem particularly useful so will not do in this PR

raise(
SyntaxError(
loc,
"To use partial application, prefix the function call with `partial`.",
Copy link
Member Author

@alex-snezhko alex-snezhko Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was kind of a bandaid fix around me being a noob with LR(1) parsers and not being able to figure out how to create separate rules for partial and total applications without reduce/reduce conflicts. If anyone has insight on how to do this please let me know

@ospencer ospencer changed the title feat(compiler): Partial function application feat(compiler)!: Partial function application Apr 19, 2024
@ospencer
Copy link
Member

Marked this as breaking because of the new keywords.

@alex-snezhko alex-snezhko marked this pull request as draft May 9, 2024 14:08
@alex-snezhko alex-snezhko marked this pull request as ready for review July 20, 2024 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lang: partial operator
3 participants