# Differences between \`foldl\` and \`foldr\`

**URL:** <https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744>\
**Category:** Links\
**Created:** [September 26, 2026, 10:04am UTC](https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744 "2026-09-26T10:04:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kleidukos](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/kleidukos/32/1213_2.png) [@Kleidukos](https://discourse.haskell.org/u/Kleidukos)\
**Post date:** [September 26, 2026, 10:04am UTC](https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744/1 "2026-09-26T10:04:37Z")

</div>

This article is a reproduction of a seminal explanation by Alexis King 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](https://github.com/hasura/graphql-engine/pull/2933#discussion_r328821960) 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.

> **[Differences between \`foldl\` and \`foldr\` | The Haskell Programming Language's...](https://blog.haskell.org/foldl-and-foldr/)**
>
> \`foldl\` and \`foldr\` can be confusing, so let's work out what's up

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [September 26, 2026, 1:27pm UTC](https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744/2 "2026-09-26T13:27:47Z")

</div>

Thanks for publishing this in a more easily accessible form than a GitHub comment!

I’m not sure if we have a policy about posting exactly the same reply across multiple channels. I made a response [on Reddit](https://old.reddit.com/r/haskell/comments/1wqmsux/differences_between_foldl_and_foldr/pc617qb/) but won’t copy and paste it here unless a mod says that’s OK.

---

<div class="post-metadata">

**Author:** ![BurningWitness](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/burningwitness/32/3665_2.png) [@BurningWitness](https://discourse.haskell.org/u/BurningWitness)\
**Post date:** [September 26, 2026, 1:51pm UTC](https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744/3 "2026-09-26T13:51:14Z")

</div>

From the very first sentence, I don’t like how the post wants to be an explanation of folds _in general_ with constant caveating that the explanation only applies to lists. It inevitably culminates in

> [@](#):
>
> Never use `foldl` or `foldr'`; they’re always worse on lists.

None of the post is wrong to be pedantic, just… can we use some different data structure next time?

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [September 26, 2026, 2:00pm UTC](https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744/4 "2026-09-26T14:00:37Z")

</div>

What different data structure were you thinking of? Exactly the same analysis of `foldl'` versus `foldr` applies to `Seq` or `Vector`. (The `foldl` versus `foldr'` part doesn’t necessarily, but it’s ambiguous what those should mean on data structures that can be walked from both ends).

---

<div class="post-metadata">

**Author:** ![BurningWitness](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/burningwitness/32/3665_2.png) [@BurningWitness](https://discourse.haskell.org/u/BurningWitness)\
**Post date:** [September 26, 2026, 2:25pm UTC](https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744/5 "2026-09-26T14:25:51Z")

</div>

Yes, because the thing that you want to tease out in the article is the evaluation order of lazy and strict folds (which can be demonstrated over any foldable data structure), not directionality (which is egregiously skewed specifically in the case of lists).

A good example type would be one would be one that is trivial to manipulate directly, even if it would never be constructed manually. A [spine-lazy PATRICIA tree](https://hackage.haskell.org/package/radix-tree-1.1.0.0/docs/src/Data.Patricia.Word.Lazy.Internal.html#LazyPatricia), perhaps. An immutable array would also work (though `base` should provide proper arrays; I don’t like `Vector`).

Also I don’t think there needs to be any ambiguity as to what “walking a data structure from either end” means. Folding a data structure should take constant time per element instead of leaving it up to library writers [to introduce the notion of order into the definition](https://hackage.haskell.org/package/heaps-0.4.1/docs/src/Data.Heap.html#line-411) on a whim.

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [September 26, 2026, 2:39pm UTC](https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744/6 "2026-09-26T14:39:57Z")

</div>

> [@BurningWitness](#):
>
> Folding a data structure should take constant time per element instead of leaving it up to library writers [to introduce the notion of order into the definition](https://hackage.haskell.org/package/heaps-0.4.1/docs/src/Data.Heap.html#line-411) on a whim

Agreed with that (though maybe log time rather than constant). `Foldable` has become a kitchen sink and is essentially impossible to use generically.

---

<div class="post-metadata">

**Author:** ![viktor](https://avatars.discourse-cdn.com/v4/letter/v/d6d6ee/32.png) [@viktor](https://discourse.haskell.org/u/viktor)\
**Post date:** [September 27, 2026, 3:46am UTC](https://discourse.haskell.org/t/differences-between-foldl-and-foldr/14744/7 "2026-09-27T03:46:19Z")

</div>

If some of this is more pithy or clear than the `Overview` section `Data.Foldable`, and appropriate for the haddocks, please open an MR that improves that text.
