<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/differences-between-foldl-and-foldr--tiiovwbd7" -->

---
title: Differences between `foldl` and `foldr` | daily.dev
description: A deep explanation of the difference between foldl and foldr in Haskell, clarifying that both traverse lists left to right but differ in associativity, not...
canonical: https://daily.dev/posts/differences-between-foldl-and-foldr--tiiovwbd7
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Differences between `foldl` and `foldr` | daily.dev
og:description: A deep explanation of the difference between foldl and foldr in Haskell, clarifying that both traverse lists left to right but differ in associativity, not...
og:url: https://daily.dev/posts/differences-between-foldl-and-foldr--tiiovwbd7
og:image: https://api.daily.dev/og/posts/TiIOVwbd7.png
og:image:alt: Differences between `foldl` and `foldr`
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Differences between `foldl` and `foldr`

**[Lobsters](https://daily.dev/sources/lobsters)** · 12 min read · 0 upvotes · 0 comments

## Summary

A deep explanation of the difference between foldl and foldr in Haskell, clarifying that both traverse lists left to right but differ in associativity, not direction. Covers how strict languages evaluate these folds inside-out versus how lazy languages like Haskell evaluate outside-in, why lazy foldl builds up unnecessary thunks (and why foldl' fixes this), why foldr can work on infinite lists when the reducing function is lazy in its second argument, and practical rules of thumb: use foldl' for strict accumulators, foldr for lazy ones, and avoid plain foldl or foldr' on lists. Also touches on snoc lists and trees, where the strict/lazy fold guidance flips or becomes ambiguous, and recommends foldMap' for tree-like structures.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.haskell.org/foldl-and-foldr>

## Questions this post answers

### When should I use foldl' instead of foldr in Haskell?

Use foldl' when the accumulation function is strict, since the whole list must be traversed anyway and foldl' consumes it in constant space by forcing thunks incrementally. Use foldr when the accumulation function is lazy in its second argument, since it can save work and even operate on infinite lists. Plain foldl and foldr' are rarely useful on ordinary lists.

_Developers tuning fold performance can compare strictness trade-offs like this one on daily.dev._

### Why does foldl cause memory problems in lazy languages like Haskell?

Lazy foldl builds a large nested thunk instead of reducing incrementally, because each application of the combining function is suspended rather than evaluated. For example, folding addition over a list creates a thunk like ⟨⟨⟨0+1⟩+2⟩+3⟩+4, consuming space linear in the list's size rather than constant space, which can turn an otherwise streaming computation into a memory-heavy one.

_Anyone debugging space leaks in Haskell folds can dig into explanations like this on daily.dev._

### Why can foldr work on infinite lists but foldl cannot?

foldr can operate on infinite lists because it pushes recursive calls into a leaf of the expression tree, producing results in weak-head normal form incrementally, so only as much of the list needs to be evaluated as is actually demanded. foldl always makes the recursive call the root of the expression, meaning the entire list must be traversed before anything can be produced, which fails on infinite input.

_Developers reasoning about lazy streaming semantics can find deep dives like this through daily.dev._

## Similar posts on daily.dev

- [Haskell for all: A bidirectional typechecking puzzle](https://daily.dev/posts/haskell-for-all-a-bidirectional-typechecking-puzzle-wbty7vdm3) · Planet Haskell · 0 upvotes · 0 comments
- [Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages](https://daily.dev/posts/co-creator-of-haskell-functional-programming-thinking-in-types-useless-languages-o1piocsn9) · The Developing Dev · 0 upvotes · 0 comments
- [Haskell \(Libraries\)](https://daily.dev/posts/haskell-libraries--umqiideey) · Lobsters · 0 upvotes · 0 comments
- [Lambda Days - Learning Resources / Talks - Erlang Forums](https://daily.dev/posts/lambda-days---learning-resources-talks---erlang-forums-hznvl5mu4) · Erlang Forums · 0 upvotes · 0 comments
- [Filtering Unique Items from Heterogeneous Lists at Compile Time](https://daily.dev/posts/filtering-unique-items-from-heterogeneous-lists-at-compile-time-gkt8ropff) · Jacek Galowicz · 0 upvotes · 0 comments

---

Tags: [#functional-programming](https://daily.dev/tags/functional-programming), [#haskell](https://daily.dev/tags/haskell)

[View this post on daily.dev](https://daily.dev/posts/differences-between-foldl-and-foldr--tiiovwbd7)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Differences between `foldl` and `foldr`","url":"https://daily.dev/posts/differences-between-foldl-and-foldr--tiiovwbd7","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/differences-between-foldl-and-foldr--tiiovwbd7"},"datePublished":"2026-09-30T18:54:24.215Z","dateModified":"2026-09-30T18:54:47.661Z","description":"A deep explanation of the difference between foldl and foldr in Haskell, clarifying that both traverse lists left to right but differ in associativity, not...","image":"https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001","thumbnailUrl":"https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001","isAccessibleForFree":true,"articleSection":"Lobsters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Lobsters","logo":"https://media.daily.dev/image/upload/s--tl8v_Fku--/f_auto,t_logo/v1698841318/logos/lobste.jpg","url":"https://daily.dev/sources/lobsters"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/differences-between-foldl-and-foldr--tiiovwbd7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"functional-programming,haskell","timeRequired":"PT12M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Lobsters","item":"https://daily.dev/sources/lobsters"},{"@type":"ListItem","position":3,"name":"Differences between `foldl` and `foldr`"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/differences-between-foldl-and-foldr--tiiovwbd7#faq","mainEntity":[{"@type":"Question","name":"When should I use foldl' instead of foldr in Haskell?","acceptedAnswer":{"@type":"Answer","text":"Use foldl' when the accumulation function is strict, since the whole list must be traversed anyway and foldl' consumes it in constant space by forcing thunks incrementally. Use foldr when the accumulation function is lazy in its second argument, since it can save work and even operate on infinite lists. Plain foldl and foldr' are rarely useful on ordinary lists. Developers tuning fold performance can compare strictness trade-offs like this one on daily.dev."}},{"@type":"Question","name":"Why does foldl cause memory problems in lazy languages like Haskell?","acceptedAnswer":{"@type":"Answer","text":"Lazy foldl builds a large nested thunk instead of reducing incrementally, because each application of the combining function is suspended rather than evaluated. For example, folding addition over a list creates a thunk like ⟨⟨⟨0+1⟩+2⟩+3⟩+4, consuming space linear in the list's size rather than constant space, which can turn an otherwise streaming computation into a memory-heavy one. Anyone debugging space leaks in Haskell folds can dig into explanations like this on daily.dev."}},{"@type":"Question","name":"Why can foldr work on infinite lists but foldl cannot?","acceptedAnswer":{"@type":"Answer","text":"foldr can operate on infinite lists because it pushes recursive calls into a leaf of the expression tree, producing results in weak-head normal form incrementally, so only as much of the list needs to be evaluated as is actually demanded. foldl always makes the recursive call the root of the expression, meaning the entire list must be traversed before anything can be produced, which fails on infinite input. Developers reasoning about lazy streaming semantics can find deep dives like this through daily.dev."}}]}
```

