Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Currying--useful examples?

by stvn (Monsignor)
on Jan 11, 2007 at 01:40 UTC ( [id://594042]=note: print w/replies, xml ) Need Help??


in reply to Currying--useful examples?

Currying in a functional language (as others have pointed out above) is automatic within the language. This is because in most functional languages, a function is only allowed to accept one argument. Syntactic sugar under the hood will convert a multi-parameter function like this (using pseudo-functional-perl):

sub foo $x $y { $x * $y }
into something like this:
sub foo $x { sub $y { $x * $y } }
and then function application like this:
foo(3, 5)
into this:
foo(3)(5)
This is even more obvious in the type signatures of functions in languages like OCaml or Haskell. For instance, the above foo function would have the type signature in OCaml:
val foo :: int -> int -> int
Which basically can be read as "a function which takes an int, which returns a function, which also takes an int, which then returns an int".

So, to answer your question more directly, using currying in a language like Perl has (at best) only obscure usages. But in a functional language like Standard ML, OCaml or Haskell it is a fundemental part of how the language actually works.

-stvn

Replies are listed 'Best First'.
Re^2: Currying--useful examples?
by gaal (Parson) on Jan 11, 2007 at 09:14 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 03:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found