Proposal #3999: Improved folds for Data.Map and Data.IntMap

Tyson Whitehead twhitehead at
Fri Apr 23 10:44:48 EDT 2010

On April 22, 2010 21:11:55 Roman Leshchinskiy wrote:
> That doesn't really help me, though, because I can't tell why using foldl
> as opposed to foldl' is essential (or even correct) in these cases. In
> fact, at a cursory glance a lot of them look quite leaky to me.

Here's a toy example where replacing foldl with foldl' would be wrong

sumWhile g y x | g x       = y + x
               | otherwise = 0

foldl (sumWhile (< 3)) 6 [5,undefined,4,3,2,1,0]

Perhaps there is other code where forcing values via foldl' before they are 
known to be required can be bad (due the cost or causing an exception).

Cheers!  -Tyson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url :

More information about the Libraries mailing list