gwaerondor / partial_application

Partial Function Application in Erlang
Other
2 stars 0 forks source link

Direct application of a curried function #1

Open gwaerondor opened 4 years ago

gwaerondor commented 4 years ago

Description

With normal fun syntax it is possible to directly call an anonymous function by putting parentheses after it, like this:

fun(N) -> N * 2 end(10)

Similarly, it should be possible to call a partially applied function by putting parentheses after it like this:

lists:all(is_integer(), _)([1, 2, 3])

But at the moment that will not compile, due to an unexpected ( after the "partial function call".

Solution

Compare the AST of a module where the normal anonymous function call with arguments is performed, and generate something that looks the same way with curried functions.

Pitfall

  1. The arguments applied directly to the fun can also be unknown. This should therefore return a function:
lists:all(is_integer(), _)(_)

The example is silly but for consistency with current Erlang syntax, and the functionality of this very project, there is no reason for it not to work.

  1. An explicit anonymous function definition should also support this.
fun(X) -> X * 2 end(_)

should therefore be able to return a function.