Currying: The Rationale

Hi What is the rationale behind currying? is it for breaking subroutines into pure one-to-one mappings? If f x y = f x -> a function which takes y for argument then does that mean that the second function already has value x, as it were, built into it? The syntax in Haskell is perfectly lucid and almost intuitive; unlike the underlying theory which is a bit ... top marks for the least jargoned answer. Many thanks in advance, Paul

On Wed, 23 May 2007, PR Stanley wrote:
Hi What is the rationale behind currying? is it for breaking subroutines into pure one-to-one mappings?
We don't have 'subroutines' as such, but otherwise yes. Also, it gives us partial application - we don't have to apply all the parameters at once, and we can do interesting and useful things by applying only some to get a new function.
If f x y = f x -> a function which takes y for argument then does that mean that the second function already has value x, as it were, built into it?
Yep, though I can't make sense of what your syntax is supposed to mean. -- flippa@flippac.org Society does not owe people jobs. Society owes it to itself to find people jobs.

Hi What is the rationale behind currying? is it for breaking subroutines into pure one-to-one mappings?
We don't have 'subroutines' as such, but otherwise yes. Also, it gives us partial application - we don't have to apply all the parameters at once, and we can do interesting and useful things by applying only some to get a new function.
If f x y = f x -> a function which takes y for argument then does that mean that the second function already has value x, as it were, built into it?
Yep, though I can't make sense of what your syntax is supposed to mean. I shouldn't take it too literally. It's just to illustrate the point that f x returns another function with x already in it and y passed as argument. Could you perhaps demonstrate how you can apply parts of curried functions in other functions in Haskell? Thanks, Paul
-- flippa@flippac.org
Society does not owe people jobs. Society owes it to itself to find people jobs.

On May 22, 2007, at 22:35 , PR Stanley wrote:
Could you perhaps demonstrate how you can apply parts of curried functions in other functions in Haskell?
A trivial example:
Prelude> map (+1) [1..10] [2,3,4,5,6,7,8,9,10,11]
(Strictly speaking (+1) is a section, but that's just a syntactic special case of currying.) More usefully, the same thing can be used in a State monad with the "modify" function:
Prelude Control.Monad.State> runState (modify (+1)) 1 ((),2)
While this is again a trivial example, you can use modify with a curried function or a section in more complicated examples to modify the state "in place". -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

prstanley:
Hi What is the rationale behind currying? is it for breaking subroutines into pure one-to-one mappings?
We don't have 'subroutines' as such, but otherwise yes. Also, it gives us partial application - we don't have to apply all the parameters at once, and we can do interesting and useful things by applying only some to get a new function.
If f x y = f x -> a function which takes y for argument then does that mean that the second function already has value x, as it were, built into it?
Yep, though I can't make sense of what your syntax is supposed to mean. I shouldn't take it too literally. It's just to illustrate the point that f x returns another function with x already in it and y passed as argument. Could you perhaps demonstrate how you can apply parts of curried functions in other functions in Haskell?
(^) applied to 2, produces a new function, we can map over a list: Prelude> let sq = (^2) Prelude> map sq [1..10] [1,4,9,16,25,36,49,64,81,100] or more explicitly: Prelude> let x `to` y = x ^ y Prelude> let sq x = x `to` 2 Prelude> map sq [1..10] [1,4,9,16,25,36,49,64,81,100] -- Don

PR Stanley wrote:
What is the rationale behind currying?
Given map :: (a->b) -> [a]->[b] take :: Int -> [a] -> [a] I can write "map f . take 10" or "take 10 >>> map f". Given tmap :: (a->b, [a]) -> [b] ttake :: (Int, [a]) -> [a] I have to write "\x -> tmap(f, ttake(10, x))". It is not just syntax. Syntax messes with your mind! The former invites you to see the pipeline architecture. The latter invites you to see the execution steps. The latter risks missing the forest for the trees. The great value of the former is such that C++ STL <Functional> goes to great length to bring it back to C++.
participants (5)
-
Albert Y. C. Lai
-
Brandon S. Allbery KF8NH
-
dons@cse.unsw.edu.au
-
Philippa Cowderoy
-
PR Stanley