{
  "id": 10950816,
  "title": "Differences between `foldl` and `foldr`",
  "url": "https://urgent.news/2026/09/30/differences-between-foldl-and-foldr",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-30T12:47:02.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://blog.haskell.org/foldl-and-foldr/"
  },
  "original_language": "en",
  "account": "The article, penned by Alexis King, elucidates the distinctions between `foldl` and `foldr`. These two functions, both capable of traversing structures like lists from left to right, differ in their associativity. To grasp this, the author employs an illustration: while both expressions render elements in the same order, `foldl` applies operations left-associated, whereas `foldr` does so right-associated.\n\nWhen dissecting the impact of this disparity on program behavior, the author contrasts strict and lazy languages. In strict languages, evaluation proceeds from the \"inside out.\" For instance, the strict evaluation of `foldl (+) 0 [1,2,3,4]` culminates in `((((0+1)+2)+3)+4)`, a sequence of reductions that begins with the innermost pair of parentheses. Conversely, `foldr` yields the same result but traverses the list differently, starting from the right and reducing \"backwards,\" necessitating a tail-recursive approach.\n\nIn lazy languages like Haskell, however, the situation shifts. Here, evaluation is \"outside in,\" meaning it only computes what is needed. This leads to a significant difference in behavior between `foldl` and `foldr`. For `foldl`, Haskell constructs an entire thunk chain linearly proportional to the list's size, consuming linear space. This contrasts sharply with `foldr`, which generates a single thunk, making it space-efficient even with lazy operations. The author emphasizes that `foldl'`, a stricter version of `foldl`, addresses this issue by demanding the thunk eagerly, maintaining constant space complexity. Thus, the choice between `foldl` and `foldr` hinges on the desired space efficiency and the nature of the operations involved.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}