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

Add support for partial application of uncurried functions #5805

Merged
merged 5 commits into from
Nov 16, 2022

Conversation

cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented Nov 14, 2022

An instance of the normal application rule (in standard notation) for curried function is:

f : (. t1, t2) => t   e1:t1   e2:t2
-----------------------------------
         f(. e1, e2) : t

This PR provides an additional rule, one instance being:

f : (. t1, t2) => t   e1:t1
---------------------------
    f(e1) : (. t2) => t

One immediate consequence is that instead of having a library function such as raise : exn => 'a, one can provide instead an uncurried function raise : (. exn) => 'a.
Any pre-existing client code that uses raise(E) still works because of the new rule.
In addition, new uncurried code can call the same function with raise(. E).

This opens the possibility of uncurrifying libraries without affecting existing code, for the most part, and have new uncurried code written in natural style take advantage of the uncurried definitions. One case where there is no free lunch are callbacks, as in List.map where two versions still need to be provided if two uses are required.

Now switching to uncurried by default notation. The same new rule, just written in uncurried by default notation, looks like this:

f : (t1, t2) => t  e1:t1
------------------------
  f(. e1) : t2 => t

One way to read this rule is: one can opt into partial application by using the dot notation. The net effect is that no curried types are ever created if one only uses uncurried functions and partial application.

@cristianoc cristianoc changed the title Test uncurried cast idea. Add support for partial application of uncurried functions Nov 15, 2022
When curried application is used for an uncurried function, instead of a type error one gets a curried partial application.

This allows e.g. to define curried library functions such as `raise` and use them both with curried and uncurried application.
@cristianoc cristianoc merged commit 84e8f41 into master Nov 16, 2022
@cristianoc cristianoc deleted the test_uncurried_cast branch November 16, 2022 11:06
@cristianoc cristianoc mentioned this pull request Nov 16, 2022
15 tasks
cristianoc added a commit that referenced this pull request Dec 8, 2022
This is not an error anymore since the introduction of partial application in #5805

See: #5888
cristianoc added a commit that referenced this pull request Dec 8, 2022
This is not an error anymore since the introduction of partial application in #5805

See: #5888
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.

1 participant