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
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
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
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
(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
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,
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
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