[Haskell-cafe] Lists concatenation being O(n)

Bas van Dijk v.dijk.bas at gmail.com
Fri Oct 14 17:34:05 CEST 2011

2011/10/14 Yves Parès <limestrael at gmail.com>:
> (*) Anyway, is there a place where foldl is preferable over foldl' ?

To quote http://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl' :

"Usually the choice is between foldr and foldl', since foldl and
foldl' are the same except for their strictness properties, so if both
return a result, it must be the same. foldl' is the more efficient way
to arrive at that result because it doesn't build a huge thunk.
However, if the combining function is lazy in its first argument,
foldl may happily return a result where foldl' hits an exception"

The article also contains an example.


More information about the Haskell-Cafe mailing list