[Haskell-cafe] Currying: The Rationale

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Tue May 22 22:40:17 EDT 2007


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 at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH




More information about the Haskell-Cafe mailing list