Differences Between `Foldl` And `Foldr`
AIThis post was created with the assistance of artificial intelligence (AI).

TL;DR

Prime Big Deal Days · Oct 6–7Offer from Amazon

Get school and study supplies delivered free — and shop member deals

  • Fast, free delivery on millions of items
  • Access to Prime Big Deal Days deals on October 6–7
  • Prime Video, Amazon Music and more included
Start your free Prime trial Free trial for eligible customers · Cancel anytime
As an affiliate, we earn on qualifying purchases.

The Haskell blog republished Alexis King’s explanation of foldl and foldr on Sept. 25, 2026, with permission, preserving a teaching article first published in 2019. The article explains that both traverse lists left to right but associate operations differently; in lazy Haskell, foldl can build a large chain of unevaluated computations, while foldl’ forces the accumulator as it proceeds.

The Haskell Programming Language’s blog republished Alexis King’s explanation of the differences between foldl and foldr on Sept. 25, 2026, saying the explanation had been used to teach newcomers since 2019 and was being preserved with King’s permission. The article clarifies that both functions traverse a list from left to right, while grouping operations differently—a distinction that affects evaluation and memory use in lazy Haskell.

King’s explanation centers on associativity, rather than the direction of traversal. For a list of values, foldl applies the operation in a left-associated expression: each result is combined with the next element. foldr instead groups the expression to the right, nesting the remaining list and final value inside each operation. The list’s elements still appear in their original left-to-right order.

That grouping matters in a strict language, where expressions are evaluated from their most deeply nested parts. With a strict operation such as addition, foldl can update an accumulator as it processes elements, while foldr must reach the end of the list before its nested reductions can begin. King describes the practical consequence in this setting as constant-space tail recursion for foldl, compared with stack space that grows with list length for foldr.

In lazy Haskell, however, ordinary foldl does not necessarily evaluate the accumulator at each step. It can instead build a chain of suspended computations, called thunks, whose size grows with the input. King points to foldl’ as the stricter alternative: it forces the accumulator before continuing, avoiding that accumulating chain for operations that demand their arguments. The source excerpt ends as it begins a separate discussion of lazy foldr, so it does not provide that section’s full explanation.

At a glance
reportWhen: Republished September 25, 2026
The developmentThe Haskell blog republished Alexis King’s 2019 explanation of foldl and foldr on Sept. 25, 2026, describing it as a teaching resource worth preserving.

Why Laziness Changes Memory Use

The republication addresses a common source of confusion for Haskell learners: the names foldl and foldr can suggest that they traverse a list in opposite directions. King’s explanation separates traversal order from expression grouping, helping readers reason about what a fold computes and how evaluation proceeds.

The distinction also has practical consequences. Choosing foldl because it sounds iterative does not guarantee low memory use in lazy Haskell: a deferred accumulator can retain a growing computation. The source recommends considering foldl’ when the intended behavior is to evaluate the accumulator as the list is traversed. The benefits depend on the operation and what its result demands; the excerpt does not claim that one fold is best for every task.

Amazon

Haskell foldl and foldr tutorial

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

A Teaching Explanation From 2019

The blog’s editor’s note identifies the piece as a reproduction of an explanation first published in connection with hasura/graphql-engine on Sept. 26, 2019. The note says the article had been used consistently to teach newcomers and thanks Alexis King for permission to republish it.

The Sept. 25, 2026 post is therefore a republication, rather than a newly reported change to Haskell or its fold functions. Its stated purpose is to preserve an existing teaching resource. The supplied source presents the associativity explanation and discussions of strict evaluation and lazy foldl, then cuts off during the lazy foldr section.

““we believe that it ought to be preserved in the blog.””

— The Haskell Programming Language blog, editor’s note

Amazon

lazy evaluation Haskell book

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

The Lazy foldr Account Is Incomplete

The supplied source text stops partway through its section on lazy foldr, after noting that a strict operation such as addition still requires the full list before reductions can begin. It does not include the rest of King’s discussion, so the article’s full treatment of lazy foldr cannot be assessed from this material alone.

The source also offers a conceptual account rather than benchmarks or measurements for particular programs. Actual space use depends on the operation, the structure being folded and which parts of the result are evaluated. No new language change, performance measurement or update to Haskell’s fold functions is reported in the supplied material.

Amazon

strict foldl' Haskell

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Readers Can Consult the Full Post

The blog’s next step is not specified in the supplied source. Readers seeking King’s complete explanation, particularly the portion on lazy foldr, can consult the original post linked in the source material. The excerpt gives no further publication plans or related announcements.

Amazon

functional programming list processing

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Key Questions

What is the main difference between foldl and foldr?

They group applications of the operation differently. foldl is left-associated and foldr is right-associated; both preserve the list’s left-to-right element order in the expressions described by King.

Why can foldl use more memory in Haskell?

Because Haskell is lazy, ordinary foldl can leave accumulator computations unevaluated, building a chain of thunks that grows with the list.

What does foldl’ change?

foldl’ forces the accumulator before processing the next element. For suitable operations, that avoids building the growing chain of deferred accumulator computations described for foldl.

Is the 2026 post a new explanation?

No. The blog describes it as a republication of Alexis King’s explanation first published in 2019, reproduced with her permission.

Source: hn

FALL

Fall Picks

As an affiliate, we earn on qualifying purchases.

You May Also Like

Cordless Vacuum Batteries: Why They Fade and How to Extend Life

Plugging into the secrets behind cordless vacuum battery fade can help extend their lifespan—discover how to keep your battery performing at its best.

Doorbell Camera Placement Mistakes That Ruin Useful Footage

Gaining clear, useful footage depends on proper doorbell camera placement; discover the common mistakes that could be ruining your security.

QoS Settings Explained: When They Help and When They’re Hype

Understanding QoS settings can reveal whether they truly improve your network or just create false hope—discover the facts behind the hype.

SimPolitics: America’s quest to solve politics with computers

MIT-led initiative SimPolitics aims to use computer simulations to address American political challenges, marking a significant technological approach to governance.