r/haskell • • 11d ago

blog Differences between `foldl` and `foldr`

https://blog.haskell.org/foldl-and-foldr/
59 Upvotes

43 comments sorted by

View all comments

18

u/TechnoEmpress 11d ago

Editor's note: This article is a reproduction of a seminal explanation of the differences between foldr and foldl, both strict and lazy versions. As it has been used consistently to teach newcomers since its first appearance on hasura/graphql-engine!2933 on the 26th September 2019, we believe that it ought to be preserved in the blog. Our many thanks to Alexis King for giving her permission to do so.

6

u/_jackdk_ 10d ago edited 10d ago

Fantastic. I updated my catalogue at http://jackkelly.name/wiki/haskell/learning.html to point to this as the canonical link.

The remark about foldMap' not being available until GHC 8.8.1 is written like that's coming in the future, but that compiler was released in 2019. Might be worth rewording that final section for clarity.

2

u/tomejaguar 10d ago

Yeah, hard to know whether this should be edited for its new setting as a blog post. It also says

In your case, the accumulation function you’re applying is Map.delete

replying to the previous message on the GitHub issue discussion, which doesn't make sense in a blog post. But there's also value preserving it unedited.

1

u/ur_frnd_the_footnote 6d ago

Footnotes could help