News for hackers. Stuff that matters.
Re:Understanding map, filter, and fold by gordon_syme on Monday December 24, 2012 @03:19AM (#4962269)
Good article but he makes the same mistake I did at first with foldl and foldr by saying they fold from the left and right respectively. Which leads to the mistaken thinking that foldr can't operate on infinite lists (it absolutely can, foldl can't).

It's better to think of them as left- and right-associative.

Re:Understanding map, filter, and fold by dfeltey on Monday December 24, 2012 @06:24AM (#4962543)
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.

Re:Understanding map, filter, and fold by biesnecker on Monday December 24, 2012 @07:18AM (#4962646)
Thanks 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 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. :-)