Follow <Real World Haskell> , it is said foldl'
are strict version of foldl
.
But it's hard for me to understand , what does strict
mean??
foldl f z0 xs0 = lgo z0 xs0
where
lgo z [] = z
lgo z (x:xs) = lgo (f z x) xs
foldl' f z0 xs0 = lgo z0 xs0
where lgo z [] = z
lgo z (x:xs) = let z' = f z x in z' `seq` lgo z' xs
foldl and (the strict) foldl' are close to semantically equivalent. The difference is in performance, especially when you are transversing a large list. The laziness has an overhead of building a thunk and foldl' is the more efficient way to arrive at that result because it doesn't build a huge thunk.
There is a really good article explaining this in detail on Haskell Wiki
Strict functions works like functions in C or other languages in that their arguments are generally eagerly evaluated.