[erlang-questions] LFE - Lisp Flavoured Erlang released
Kevin Scaldeferri
kevin@REDACTED
Tue Mar 11 23:41:34 CET 2008
somehow this branch of the conversation went off-list. Bringing it
back as others might be interested.
-kevin
On Mar 11, 2008, at 2:49 PM, Mats Cronqvist wrote:
> Kevin Scaldeferri wrote:
>>
>> On Mar 11, 2008, at 8:36 AM, Mats Cronqvist wrote:
>>
>>> Kevin Scaldeferri wrote:
>>>>
>>>> On Mar 11, 2008, at 1:31 AM, Mats Cronqvist wrote:
>>>>
>>>>>>>>
>>>>> IANACS(*), but i thought currying was supposed to look like this;
>>>>>
>>>>> curry(F,Arg) ->
>>>>> case erlang:fun_info(F,arity) of
>>>>> {_,1} -> fun() -> F(Arg) end;
>>>>> {_,2} -> fun(A) -> F(A,Arg) end;
>>>>> {_,3} -> fun(A,B) -> F(A,B,Arg) end;
>>>>> {_,4} -> fun(A,B,C) -> F(A,B,C,Arg) end
>>>>> end.
>>>>>
>>>>
>>>> No, that's partial application. Or, sort of reverse partial
>>>> application. Compare to the papply function I wrote.
>>>>
>>>>
>>>> -kevin
>>>
>>> like i said, i really have no idea what i'm talking about. but i
>>> found several descriptions like this;
>>>
>>> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549
>>>
>>> "In functional programming, currying is a way to bind arguments with
>>> a function and wait for the rest of the arguments to show up later.
>>> You "curry in" the first few parameters to a function, giving
>>> you a function that takes subsequent parameters as input and
>>> calls the original with all of those parameters."
>>>
>>> i'm so confused...
>>
>> So is the author of that paragraph :-). Here's a better
>> explanation from wikipedia: http://en.wikipedia.org/wiki/Currying
>>
>> "Given a function f of type f : (X x Y) -> Z , then currying it
>> makes a function curry(f) : X -> (Y -> Z) . That is, curry(f) takes
>> an argument of type X and returns a function of type Y -> Z . "
>>
>> So, what you see here is that in some sense currying is a precursor
>> to partial application.
>
> i guess you just can't trust random web pages these days... i found
> a better source of info on the haskell web (surprise!)
>
>> Part of the confusion in talking about this is that this is all in
>> the context of theories of computation where all functions are
>> unary (like the lambda calculus). In languages with arbitrary
>> arity of functions, it's a little less clear what currying means.
>> I made the choice to interpret it as converting a unary function
>> expecting a tuple into a multi-ary function. You could argue,
>> though, that maybe it should be this instead:
>>
>> curry(F) when is_function(F,2)->
>> fun(X) ->
>> fun(Y) -> F(X,Y) end
>> end.
>>
>>
>> Notice, though, that curry() doesn't actually apply any arguments,
>> it just returns a function which naturally allows partial
>> application.
>
> i see... thanks a lot for your time!
>
>>
>> -kevin
>>
>> P.S. Did you intentionally only send this to me? I think there's
>> frequent confusion about this, so it seems to be like valuable
>> discussion for the list
>>
> i did "reply all" in my trusty old thunderbird; i think your
> previous mail was sent to me only (at least it looked like that to
> thunderbird). feel free to forward any/all of this to the list. i'm
> pretty sure i'm not the only one confused by this (though i might be
> the only one that cares, of course.)
>
> mats
> <mats_cronqvist.vcf>
More information about the erlang-questions
mailing list