Re: [Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-30 Thread Ryan Ingram
The difference is that foldl *must* produce the entire list of thunks, even if f is lazy in its first argument. There's no foldl that can perform better given a sufficiently-lazy f; given head = foldr go fail where go x y = x fail = error head: empty list head [a,b,c,d] = foldr go fail

Re: [Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-25 Thread Mathieu Boespflug
Albert Y. C. Lai tre...@vex.net writes: On 12-07-23 10:52 PM, Qi Qi wrote: Foldl has the space leak effect, and that's why foldl' has been recommended. foldr (+) and foldl (+) for Int have the same asymptotic costs, both time and space. See my http://www.vex.net/~trebla/haskell/lazy.xhtml

Re: [Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-25 Thread Albert Y. C. Lai
On 12-07-25 09:06 AM, Mathieu Boespflug wrote: Albert Y. C. Lai tre...@vex.net writes: foldr (+) and foldl (+) for Int have the same asymptotic costs, both time and space. See my http://www.vex.net/~trebla/haskell/lazy.xhtml Therefore, I do not understand why they are labeled opposite

Re: [Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-24 Thread Albert Y. C. Lai
On 12-07-23 10:52 PM, Qi Qi wrote: Foldl has the space leak effect, and that's why foldl' has been recommended. foldr (+) and foldl (+) for Int have the same asymptotic costs, both time and space. See my http://www.vex.net/~trebla/haskell/lazy.xhtml Therefore, I do not understand why they

[Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-23 Thread Qi Qi
Hi, I wonder why a foldr does not have a space leak effect? Any hints? Thanks. Qi ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-23 Thread Ivan Lazar Miljenovic
(Trying again using the real mailing list address rather than google groups) On 24 July 2012 12:37, Qi Qi qiqi...@gmail.com wrote: Hi, I wonder why a foldr does not have a space leak effect? Any hints? Thanks. Why should it? Does it not depend on the function you're folding, the type of

Re: [Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-23 Thread Qi Qi
Foldl has the space leak effect, and that's why foldl' has been recommended. On Monday, July 23, 2012 9:44:59 PM UTC-5, Ivan Lazar Miljenovic wrote: (Trying again using the real mailing list address rather than google groups) On 24 July 2012 12:37, Qi Qi qiqi...@gmail.com wrote: Hi,

Re: [Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-23 Thread Ivan Lazar Miljenovic
On 24 July 2012 12:52, Qi Qi qiqi...@gmail.com wrote: Foldl has the space leak effect, and that's why foldl' has been recommended. foldl can have a space leak due to accumulation of thunks: foldl f a [b,c,d] = f (f (f a b) c) d ^^ Building up a chain of functions. As such, these thunks are

Re: [Haskell-cafe] why does a foldr not have a space leak effect?

2012-07-23 Thread Qi Qi
This question actually was risen when I read a relevant part in the RWH book. Now it's much clearer to me. Thanks Ivan! On Monday, July 23, 2012 10:04:00 PM UTC-5, Ivan Lazar Miljenovic wrote: On 24 July 2012 12:52, Qi Qi qiqi...@gmail.com wrote: Foldl has the space leak effect, and that's