On Sun, Sep 21, 2014 at 7:05 PM, Dimitri DeFigueiredo <defigueiredo@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ï