by gordon_syme · 13y ago · 0 comments
It's better to think of them as left- and right-associative.
Defining any' as
any' f xs = foldl (\acc x -> f x || acc) False xs
Then trying to evaluate any' even [1..] runs forever, but if we modify it slightly to use foldr instead as
any' f xs = foldr (\x acc -> f x || acc) False xs
Then evaluating any' even [1..] terminates basically immediately with True.
I'll update the post with a correction, and eventually write a "how I learned to stop worrying and love the difference between foldl and foldr" post. :-)