Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^3: Specializing Functions with Currying

by diotalevi (Canon)
on Aug 06, 2004 at 15:25 UTC ( #380597=note: print w/replies, xml ) Need Help??

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

Ok, well my understanding of computer science is limited. In perl we implement currying with anonymous function and as such, talk about anonymous functions much more often than currying. What part of currying in perl am I not understooding when I say "anonymous function?" Also, what part of language/implementation independent currying am I not understanding when I think of an anonymous function in perl?

I changed my term from "closure" to "anonymous function" because while closures are anonymous functions, they go slightly farther by having a lexical environment and anonymous functions don't necessarily have that.

  • Comment on Re^3: Specializing Functions with Currying

Replies are listed 'Best First'.
Re^4: Specializing Functions with Currying
by jryan (Vicar) on Aug 06, 2004 at 20:10 UTC

    "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.

      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.

        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.

        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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://380597]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2017-05-23 06:12 GMT
Find Nodes?
    Voting Booth?