[Haskell-beginners] what space leak could happen here?
Dimitri DeFigueiredo
defigueiredo at ucdavis.edu
Sun Sep 21 20:12:04 UTC 2014
Thanks!
I don't quite understand the last sentence, though. So, it is a leak
just because it needs to evaluate an element that may not be required? I
thought a space leak implied we would be changing the "Big O" asymptotic
order of space usage. How would the extra evaluation would change that?
Thanks again,
Dimitri
On 21/09/14 13:20, Chaddaï Fouché wrote:
> On Sun, Sep 21, 2014 at 7:05 PM, Dimitri DeFigueiredo
> <defigueiredo at ucdavis.edu <mailto: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ï
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140921/5e52412e/attachment.html>
More information about the Beginners
mailing list