Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Specializing Functions with Currying

by jryan (Vicar)
on Aug 06, 2004 at 20:10 UTC ( #380700=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Specializing Functions with Currying
in thread Specializing Functions with Currying

"Currying" does not mean "using an anonymous function", it means "partial application of function arguments." It's kind of like saying "I know that I'm going to call this function with these first few arguments, so let me half-call it now so that I don't have to worry about them later." Perl's OO system sort of has transparent currying aspect to it. Each method call is just a function call automatically curried with one argument (the object that the method was called upon) and then called. For a more concrete application of currying, you could check out this old node by mirod.


Comment on Re^4: Specializing Functions with Currying
Re^5: Specializing Functions with Currying
by diotalevi (Canon) on Aug 06, 2004 at 20:45 UTC

    Yes... I see that and still keep thinking "boy, this is pretty normal perl stuff". find( sub { wanted( @my_args, @_ ) }, ... ) is already easy to use and I don't see the utility in going out of the way to inject extra obfuscatory language just to describe it.

      I don't see the utility in going out of the way to inject extra obfuscatory language just to describe it

      It's only obfuscatory if you don't know what the terms mean :-) If you do then the utility is more information on the intent.

      If somebody refers to a curried function then I know that they're going to be taking a function and specialising it by freezing one of its arguments. This tells me more than if they had referred to it as a closure.

      You're right that coming up with language to describe what you want often doesn't pay back when you are limited to a single tool that works how it works.

      But it pays back in spades when you are considering what you can do with different sets of tools. And it is indispensable when you're trying to design a tool.

      In Perl 5 it practically isn't worth the bother to think, "Oh, I could do this with currying" - you just do it with a closure and avoid the extra step. But if you know how to think about what you're doing as currying, then when you use a language with good support for currying, you will have some notions on when to reach for that rather than writing it in Perl 5. Alternately if you are working in a language that without support for closures, but you understand that all you really want is currying, then you can figure out ways to simulate the simpler concept rather than trying to do full-blown closures.

      Furthermore when it comes to designing tools, well have you read Perl 6 : Not Just For Damians? Take a look at the example of currying offered there. If Larry and Damian et al did not have language to discuss the idea of currying, would they ever have thought up such a nice way to do it?

      So yes, learning about currying is completely useless to you in day to day Perl 5 programming. But concluding that it is therefore a useless concept is a fast way to fall into the "Blub Paradox". See Beating The Averages if you don't know what that is.

        This is to both you and adrianh.

        I have apparently misinterpreted this as thoughts on perl5 practice and constrained myself to that universe. Implicltly, I've thought that if I were in some other language where currying was standard I'd think along those lines. In this language (perl5), I don't and so I didn't and I objected with my initial request for a terminology change.

        I do however, take to heart your bringing up that issue of language power and the perspective limiting aspect of being proficient in a language. In fact, I've often read all these functions returning other functions composed of other functions, wrapping other functions and felt really quite swimmy. Very lost. Suddenly I'm reminded of E and their Promises and the "So when does something *happen*?" and it makes more sense.

        Thanks. This was useful to me. I just gained a new way to think about this stuff.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://380700]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-09-02 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (22 votes), past polls