[Haskell-cafe] Re: Currying and Partial Evaluation

Achim Schneider barsoap at web.de
Tue Jan 8 18:51:55 EST 2008


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:

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.


-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 



More information about the Haskell-Cafe mailing list