[erlang-questions] will Erlang ever have currying?

t ty tty.erlang@REDACTED
Wed Sep 6 04:37:48 CEST 2006


I usually use currying for a cheap form of partial evaluation. One
simple operation I have is to test that two list matches. One list is
actually fix for a particular run, while I may have several hundred
thousands of the second parameter in the run.

Also my list matching is rather complicated, first element match,  two
consecutive elements matches, first and last element matches etc. With
currying I personally find it easier to read/reason. I might also have
a slight speed increase but haven't really tested for this scenerio.

Yes, I am a funs fan.

t

> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list