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

Draft
wants to merge 1 commit 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

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

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

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
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

Successfully merging this pull request may close these issues.

Lang: partial operator
2 participants