[erlang-questions] will Erlang ever have currying?

Bob Ippolito bob@REDACTED
Wed Sep 6 03:53:27 CEST 2006


On 9/5/06, Yariv Sadan <yarivvv@REDACTED> wrote:
>
> I couple of my functional programmer friends have complained about
> Erlang's lack of currying. (One of them has even described currying as
> "more addictive than heroin without the nasty effects" :) ). I didn't
> get a "final" answer last time I asked this question, so I'd like to
> ask it again (at least so I have an intelligent answer to give to
> others): will Erlang ever have currying?
>
> This is the kind of currying I mean, in pseudo code:
>
> F = fun(A,B) -> A+B end.
> F1 = F(2).
> true = F1(3) == 5.

What do they actually use currying for? Do you have any examples of
code that's better expressed via currying rather than just making a
fun? Implicit currying in Erlang seems like a Really Bad Idea to me...

It'd certainly be possible to implement explicit currying like this:

curry(Fun, Arity) ->
    curry(Fun, Arity, []).

curry(Fun, 0, Args) ->
    apply(Fun, lists:reverse(Args));
curry(Fun, Arity, Args) ->
    fun (Arg) -> curry(Fun, Arity - 1, [Arg | Args]) end.

test() ->
    F0 = curry(fun (A, B, C, D) -> {A, B, C, D} end, 4),
    F1 = F0(1),
    F2 = F1(2),
    F3 = F2(3),
    {1, 2, 3, 4} = F3(4).

I haven't been using Erlang all that long, but this isn't something I miss...

-bob



More information about the erlang-questions mailing list