Haskell laziness is also a memory-retention policy
Lazy evaluation lets Haskell defer work and consume streams incrementally, but a deferred computation can retain data and accumulate. Strict folds help only when their forcing depth matches the accumulator you intend to keep.
A deferred value can save work or keep work alive
Haskell’s non-strict evaluation lets a function use only the parts of an argument it needs. GHC normally implements this with call-by-need: an unevaluated expression, often called a thunk, can be shared and evaluated when its value is demanded. That is why a consumer can take a prefix from an infinite list without constructing the rest. Laziness is a useful control over when computation happens, rather than a promise that computation or storage disappears. [1] [2]
The same delay can extend the lifetime of its inputs. A closure that represents “finish this calculation later” may still point to the data needed to finish it. If a program stores a small-looking result that references a large input, the input may remain reachable until that result is evaluated or discarded. This is a retention problem: the relevant question is not just how many values have been computed, but which unevaluated computations still hold references to them.
A left fold can build a computation instead of a result
A common example is foldl (+) 0 values. A lazy left fold can produce a chain resembling (...((0 + x1) + x2) + x3). It traverses the list while leaving the intermediate accumulator applications unevaluated; when the final number is demanded, the chain must then be reduced. The Data.List documentation describes this as a thunk chain that grows with the input. For a large finite input, that deferred work can consume substantial memory and may put pressure on the stack when finally evaluated. [3]
For a strict numeric reduction, foldl' is usually the appropriate starting point. It evaluates each step’s accumulator to weak head normal form before continuing. For an Int, reaching that outermost numeric value evaluates the arithmetic result, so the fold does not retain a linearly growing chain of additions. This changes when work is performed: each step pays the reduction cost as it proceeds, instead of postponing it until the end. It does not change the fact that a left fold must consume a finite input completely.
Weak head normal form stops at the outer constructor
Weak head normal form is a deliberately shallow stopping point. For a pair such as (count, total), evaluating the pair to an outer constructor does not necessarily evaluate count or total. A fold over a pair can therefore replace one long thunk chain with unevaluated work inside one or both fields. The outside of the accumulator looks ready while its contents remain deferred. GHC’s guide makes the same boundary explicit: a bang pattern forces its expression to weak head normal form, and a bang on one component need not force its neighbors. [2]
When a record represents ongoing numeric state, make the intended fields strict if that is the policy. For example, a Stats record with strict Int and Integer fields, updated inside a foldl', tells each update to reduce those fields rather than carry their arithmetic forward. A bang pattern on the new state can also force its outer constructor; strict field declarations are what ensure that the stored counters themselves are evaluated. The Haskell report defines strictness flags on constructor fields, and GHC’s StrictData extension can apply strict-by-default fields within a module. [1] [2]
Strictness changes behavior as well as residency
Forcing a value earlier can make an error appear earlier. If an accumulator contains a computation that would fail, a strict fold or field can expose that failure during the fold instead of when a later consumer inspects the result. It can also do unnecessary work if a value is ultimately ignored. That is why adding bangs everywhere is not a sound general optimization: strictness is an evaluation policy with consequences for timing, exceptions, and productivity.
A right fold often has a different role. When its combining function can produce an answer without evaluating the rest of the accumulator, foldr can consume a finite prefix of an infinite list. Replacing it mechanically with a strict left fold would destroy that behavior, since a left fold must reach the end of its input. Choose by the shape of the computation: a strict finite reduction for a single aggregate, or a lazy producer/consumer pipeline when early output and partial input are part of the design. [3]
Measure the retained state you mean to keep
When memory grows in a Haskell service, first find which value is retaining the input: an accumulator, a closure in a queue, a cached result, or an output list that has not been consumed. Then inspect the shape of that value. A strict fold addresses an unevaluated accumulator; strict fields address delayed components; neither removes a deliberately retained list or an unbounded cache. Check residency and allocation on a representative workload before and after the change, and keep a test for lazy behavior that callers rely on.
The useful design rule is local: keep laziness where deferred or partial computation is valuable, and add strictness at state boundaries where the program must retain a compact, evaluated summary. foldl' is a tool for one such boundary, not an automatic constant-space guarantee. The accumulator’s structure, its fields, and the consumer that holds it together determine whether memory can be released.