TL;DR
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
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.
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.
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.
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
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.
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.
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 Picks
fall essentials
As an affiliate, we earn on qualifying purchases.
