4 ms·
This was my one complaint as well, and it happens with the example given of any' Defining any' as any' f xs = foldl (\acc x -> f x || acc) False xs Then tryi
by dfeltey 14y ago
This was my one complaint as well, and it happens with the example given of any'
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.
- biesnecker 14y agoThanks much for the feedback. I clearly didn't understand them as well as I thought I did, though after reading http://stackoverflow.com/a/3085516/337184 http://stackoverflow.com/a/3085516/337184 I think I understand a bit more. 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. :-)