-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
base: main
Are you sure you want to change the base?
Conversation
TODO:
|
raise( | ||
SyntaxError( | ||
loc, | ||
"To use partial application, prefix the function call with `partial`.", |
There was a problem hiding this comment.
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
Marked this as breaking because of the new keywords. |
4b29cba
to
cae92f1
Compare
cae92f1
to
8f118ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a few questions mostly on the dummy locations, looks great overall though.
| ArgumentHole(_) => | ||
raise( | ||
SyntaxError( | ||
loc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we point to the arg.ppaa_loc
? I feel like this error might be a little annoying as it isn't immediately clear that the _
hole is specific to partial application, at least that way the position would be telling you hey this argument is the issue specifically, an alternate here would be Hole patterns are only allowed under partial application, prefix the function call with partial.
which is a bit more specific and searchable.
}; | ||
|
||
( | ||
Expression.ident( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we give all this stuff the location from the arg.
|
||
let body = | ||
Expression.apply( | ||
~loc=Location.dummy_loc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this take the location from the func
?
|
||
let new_func_params_pat = | ||
Pattern.tuple( | ||
~loc=Location.dummy_loc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
switch (l) { | ||
| Default(_) => | ||
// omitted optional argument | ||
(l, option_none(env, instance(env, ty), Location.dummy_loc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this take the location from ty
?
let pf = partial f(1, _, y=_) | ||
pf(3, 2) | ||
|}, | ||
"1\n2\n3\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a sanity check can we just add a print("0")
between the partial application and the actual application of the function i think it's obvious that it will only call the function afterwards but I feel like we should still double check that.
@@ -385,4 +385,173 @@ truc()|}, | |||
|}, | |||
"which has a default value, but the matching argument does not.", | |||
); | |||
|
|||
assertRun( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a test where a module provides a partially applied function, also maybe a clear test where a function returns a partially applied function. something like:
let f = (x, y) => {
let t = (a, b) => x + a + b
let y = partial (_, y)
y
}
print(f(1, 2)(3)) // 6
this ensures that we don't break closures and ensures that we are not losing the partial information when returning from a scope (The way this is implemented I don't think those are major concerns but they seem like good sanity checks. I think your test with the pipeline operator somewhat tests this but doesn't test closures.
switch (label) { | ||
| Labeled(name) | ||
| Default(name) => name | ||
| Unlabeled => mknoloc("$arg" ++ string_of_int(i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was having a little trouble visualizing what is actually happening here are we building a tuple from the arguments and then passing the tuple around and at the end passing the tuple values to the function when its fully applied? or did I misunderstand the abstraction here?
assertRun( | ||
"partial13", | ||
{| | ||
let (|>) = (x, f) => f(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this function to pervasives? I feel like the moment we add partial application we are going to be asked for a pipeline operator soon after we add this.
Partial function application
Closes #402