[Haskell-cafe] Re: Currying and Partial Evaluation

Derek Elkins derek.a.elkins at gmail.com
Tue Jan 8 18:38:31 EST 2008


On Wed, 2008-01-09 at 00:51 +0100, Achim Schneider wrote:
> Fernando Rodriguez <frr149 at easyjob.net> wrote:
> 
> > 
> > Hi,
> > 
> > Is currying in Haskell the same thing as Partial Evaluation
> > (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I getting
> > partial evaluation for free just by using Haskell? 
> > 
> No, currying is this:

No, it is not.  This is partial application.  See the wiki page Neil
referenced.

> 
> Prelude> let f x y = 1 + x * ( y - 3 )
> Prelude> let g = f 1
> Prelude> let h = f 2
> Prelude> g 1
> -1
> Prelude> g 2
> 0
> Prelude> h 1
> -3
> Prelude> h 2
> -1
> 
> or, a bit more confusing and possibly enlightening,
> 
> Prelude> let y f = f $ y f
> Prelude> :t y
> y :: (b -> b) -> b
> Prelude> let fixpoint f n = if n <= 1 then 1 else n * (f $ n - 1)
> Prelude> :t fixpoint
> fixpoint :: (Num b, Ord b) => (b -> b) -> b -> b
> Prelude> let fac = y fixpoint
> Prelude> :t fac
> fac :: Integer -> Integer
> Prelude> fac 10
> 3628800
> 
> Prelude> fac 100
> 9332621544394415268169923885626670049071596826438162146859296389521759999
> 3229915608941463976156518286253697920827223758251185210916864000000000000
> 000000000000
> 
> Note that "fixpoint 3" won't work, and that's good.
> 
> 



More information about the Haskell-Cafe mailing list