-
-
Notifications
You must be signed in to change notification settings - Fork 25
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): wrap partial application in anonymous functions #92
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2238b38
feat(compiler): wrap partial application in anonymous functions
michallepicki d7a121f
fix test
michallepicki e584bf4
add failing test for broken specs
michallepicki 568c0e4
remove empty file
michallepicki cc25661
remove incorrect test, use shorter generated variable names
michallepicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If I understand this correctly, you're
Uncurry.uncurry_tarrow/2
I think this will break for named and default arguments, so we need to have another look at this.
This can be problematic because fun's in Erlang can have a single arity, but multiple clauses. This means that a function
f ?(x = 1) y = x + y
would translate to 2 erlang functions:And a function with named arguments like
f ~x ~y = x / y
would need to be kept track until is fully applied before we can call it.For example, what does
let div_one = (f ~y: 1)
translate to?I think we may need to take a step back and rethink this. It's turning out to be a tad more complex than I thought id' be at first 😅
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.
which are not supported right now anyway, but I understand we should think ahead...
Gleam supports labeled arguments, and I think those are probably fine to figure out at Caramel compilation time. Not sure about default arguments, they indeed seem tricky. What values are allowed? Just simple literals? If so then maybe they are just in the typedtree and could be fetched from there and printed when needed...
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 would propose only generate the full arguments version in the resulting Erlang, so only support optional / labeled arguments when called in from Caramel, not other langs.
This depends on the way f was declared, because of the order, and the rules of Ocaml erasure would need to be preserved. So assuming it is
f x ~y = x + y
which in erlang is just f(X, Y), thenand if
f ~y x = x + y
thenfun (X) -> f(1, X) end,
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.
Or even generate the erlang functions with smaller arity for optional arguments, but only for erlang/elixir interoperability (don't use them from caramel because it's unnecessarily complicating things), and only if there is just one optional or have some rules like Elixir that they can be ommited inclusively starting from the end only.
In any case I think we can figure it out and if not, caramel is not 1.0 anyway :)