News for hackers. Stuff that matters.
Re:Differences Between `Foldl` and `Foldr` by tome on Monday October 05, 2026 @01:11PM (#49967568)
Yes, because foldr is equivalent to for_, that is, iterating over a container and performing an effectful action (what in other languages would be called "doing something") for each element. Uses of foldr can always be rewritten to uses of for_, and I find things much clearer in terms of for_!

(This is explained in my article "foldl traverses with State, foldr traverses with anything": https://h2.jaguarpaw.co.uk/posts/foldl-traverses-state-foldr...)

Re:Differences Between `Foldl` and `Foldr` by Twey on Monday October 05, 2026 @06:26PM (#49971683)
Well, `foldr` is (up to interdefinability) just the implementation of `for_` (or `traverse`) in the case of lists, in the same way that `map` is the implementation of `fmap`. The point of `traverse` is that it's provided by the functor.

The question of whether to use the most generic (for consistency) or the least generic (for directness) name for a function is the old bugbear of the Prelude :)

Re:Differences Between `Foldl` and `Foldr` by tome on Tuesday October 06, 2026 @09:49AM (#49978467)
I don't quite follow. `fmap = map` is a valid implementation for lists indeed, but `for_ = foldr` is not. They don't have compatible types, for one thing. What do you mean?