Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Specializing Functions with Currying

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

in reply to Specializing Functions with Currying

I would have just said this in perlish instead of Haskelish. I think you'll communicate better to perl people if you stop using the verb currying and use the noun closure instead. Its just the perl localism and it is how they are typically talked about.

bold => sub { wrap_with_html( b => @_ ) }; # vs bold => curry \ &wrap_with_html => 'b';

Replies are listed 'Best First'.
Re^2: Specializing Functions with Currying
by tilly (Archbishop) on Aug 06, 2004 at 18:44 UTC
    Using the wrong word will not help you communicate.

    Talking about currying is not exactly the same as talking about closures. Currying is a specific programming technique that can be implemented with closures. Currying is the idea that if I have some arguments for a function now, and will have more later, that I can right now generate a closure that has pre-bound some arguments and avoid having to pass around the arguments everywhere. Thus a curried function is a specific type of closure. A closure is somewhat more general though - for instance you can have multiple closures that privately communicate through their shared environment.

    The distinction may become more apparent in Perl 6 because they are adding support to give a direct syntax for currying. And you'll see that sometimes that syntax is enough, and other times you'll want to do extra work and create a closure by hand. (In Perl 5, of course, when you want to curry it is often simpler just to create a closure by hand.)

Re^2: Specializing Functions with Currying
by zby (Vicar) on Aug 06, 2004 at 07:45 UTC
    I find your example simpler than the original. But I need to object the dismissal of the verb 'currying' as it is a very basic vocabulary from Computing Science, much more basic than 'closure'.

      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.

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

Re^2: Specializing Functions with Currying
by FoxtrotUniform (Prior) on Aug 06, 2004 at 22:18 UTC

    Fair enough. It's not the case that currying is equivalent to making a closure, though (currying is more specific), but that's a minor point. The idea here is to describe a way to avoid the parameter-handling that comes with general-purpose functions, with as little lookup fuss as possible.

    More generally, I'm turning into a functional-programming evangelist, and since Perl makes it easy to use a lot of my favourite techniques I'm writing about them here. Go up a meta-level from my OP, and what I'm talking about is building functions on an ad-hoc basis (compare to the static "functions are global named objects and part of the design document" world of straight procedural programming). Whether you use literal subs or build higher order functions to do it is less important than being aware of the possibility.

    F o x t r o t U n i f o r m
    Found a typo in this node? /msg me
    % man 3 strfry

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2017-09-19 15:29 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (222 votes). Check out past polls.