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):
into something like this:sub foo $x $y { $x * $y }
and then function application like this:sub foo $x { sub $y { $x * $y } }
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:foo(3)(5)
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".val foo :: int -> int -> 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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Currying--useful examples?
by gaal (Parson) on Jan 11, 2007 at 09:14 UTC |