From: "S. Alexander Jacobson" <[EMAIL PROTECTED]>
Subject: Re: what is leaking?
Date: Fri, 26 Jun 1998 16:38:12 -0400 ()

> Wow! If Ralf is right, then foldl in a lazy language always generates a
> space leak and should be avoided in favor of strictFoldl.  
> 
> However, I still am not clear why explicity strictness is required for
> foldl to behave properly.  In fact it seems like the problem is
> insufficient laziness.


If you evaluate 

> let tc x y = if x == 5 then bot else x:y; bot = bot in foldl (flip tc) [] [1..10]

in Hugs you get 

[10, 9, 8, 7, 6

and then you may wait forever. If in the above you use foldl' you do
not get any output. This is due to the fact that in the latter case
even to get a WHNF for the entire expression it is necessary to
evaluate (flip tc 5 6), whereas in the former case it suffices to
construct a closure of (flip tc 5 6) without evaluating it yet.

Marko


Reply via email to