[Haskell-beginners] what space leak could happen here?

Chaddaï Fouché chaddai.fouche at gmail.com
Sun Sep 21 19:20:04 UTC 2014


On Sun, Sep 21, 2014 at 7:05 PM, Dimitri DeFigueiredo <
defigueiredo at ucdavis.edu> wrote:

> I don't understand why we need to "make every element in the
> 'intersperse'd list available as soon as possible to avoid space leaks."
> Could somebody shed some light on what could cause a space leak here? In
> particular, would this simpler version cause problems?
>

This is delicate but basically your version needs to force the second
element of the list (to check if it's []) before it produce the first
element of the result while the base version doesn't, check with "take 1 .
intersperse ',' $ 'a' : undefined".

The leak can occur when you only need the first element of the result to
start producing but the second one is expensive to produce and store, the
base version avoid the problem by being maximally lazy.
-- 
Jedaï
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140921/9a2117a2/attachment.html>


More information about the Beginners mailing list