[Haskell-cafe] Thoughts about currying and optimisations
Yves Parès
limestrael at gmail.com
Tue May 31 22:41:58 CEST 2011
> It can introduce space leaks if the computationally expensive test is
replaced with a reference to a space expensive value.
You mean if the rest of stuffX's body keeps a reference to that value, I
suppose? (I suppose, or else that value would be useless).
Ok, so GHC does detect that case and optimizes it.
2011/5/31 Edward Z. Yang <ezyang at mit.edu>
> I believe this transformation is called the 'full laziness' optimization.
> It can introduce space leaks if the computationally expensive test is
> replaced with a reference to a space expensive value.
>
> Edward
>
> Excerpts from Yves Parès's message of Tue May 31 15:14:07 -0400 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
> >
> > Whereas:
> > 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/f7f01762/attachment.htm>
More information about the Haskell-Cafe
mailing list