On 11/1/05, Scherrer, Chad <[EMAIL PROTECTED]> wrote: > I was wondering... In my experience, it's worked much better to use > > sum' = foldl' (+) 0 > > than the built-in "sum" function, which leaks memory like crazy for > large input lists. I'm guessing the built-in definition is > > sum = foldr (+) 0 > > But as far as I know, (+) is always strict, so foldl' seems much more > natural to me. Is there a case where the build-in definition is > preferable?
The library definition in ghc actually uses foldl. It's conceivable that you may not want (+) to be non-strict for certain data types. The question then becomes, is there a case where you want _sum_ to be non-strict? /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 _______________________________________________ Haskell mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell
