[Haskell-cafe] Thoughts about currying and optimisations

Yves Parès limestrael at gmail.com
Tue May 31 21:14:07 CEST 2011

Hello Café,
An idea came to me: unless the compiler notices that stuffA and stuffB are
equivalent, would it be correct to suppose that A is better than B?

stuffA x = if someComputationallyExpensiveTest x
    then doSomething else doSomethingElse

stuffB x y = if someComputationallyExpensiveTest x
    then doSomething y else doSomethingElse y

I explain: in stuffA, the function only depends on x, so when doing:
a = stuffA xxx
runs the expensive test once and for all, and a can directly be bound to
doSomething or doSomethingElse
so calling after:
a foo
a bar
won't run the test

b = stuffB xxx
is valid due to curryfication, but:
b foo
b bar
will both run the expensive test
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110531/d4e99821/attachment.htm>

More information about the Haskell-Cafe mailing list