The fold passes each returned record to the next call.The callback, folded over ticks: 100000 inputsCodeacc: _: { total = acc.total + 1; }One call: the callback builds the next recordAccumulator{ total = 0; }the initial recordcallbackNext accumulator{ total = acc.total + 1; }a new recordbecomes acc in the next call
What happens when we ask this fold for its result?result is the record returned by a fold that adds one to a total 100000 times.Which fields are in the result?builtins.attrNames result?EvaluateExplore codeWhat is the final total?result.total?EvaluateExplore codeHaving the record does not mean its total has been computed.
What does this strict fold evaluate?One record per input; ticks has 100000 itemsCoderesult = builtins.foldl' (acc: _: { total = acc.total + 1; }) { total = 0; } ticks;Empty sourcefoldl' evaluates each record; its total stays deferredrecordtotal00next callrefers to1total[0] + 12total[1] + 1computed numberdeferred expressionevaluated recordThree records shown; total[k] is the total of record k.Reading the final total climbs through every deferred additionReading the final total climbs through every deferred additionBuilding the states returns after each step without evaluating any total. Reading the final total forces the previous total, which forces the one before it. Each forced addition waits inside the previous one until the evaluator reaches its stack limit.1234stack limittotal[n−2]total[n−1]total[n]⋯stack overflowevaluatorfold ticksread result.totalforcing depthReading the final total climbs through every deferred additionBuilding the states returns after each step without evaluating any total. Reading the final total forces the previous total, which forces the one before it. Each forced addition waits inside the previous one until the evaluator reaches its stack limit.1234stack limittotal[n−2]total[n−1]total[n]⋯stack overflowevaluatorfold ticksread result.totalforcing depthIllustrative trace for n steps; the recorded run overflows at n = 100000.First call: compute 1 before returning the recordrecordtotal00next callrefers to11next?computed numberdeferred expressionevaluated recordThree records shown; total[k] is the total of record k.Each call carries a computed numberrecordtotal00next callrefers to1122computed numberdeferred expressionevaluated recordThree records shown; total[k] is the total of record k.Each step computes its total before the next beginsEach step computes its total before the next beginsEvery step forces its own addition, one level deep, because the previous total is already a number. Reading the final total then needs no chain of earlier additions.1234stack limittotal[n]100000⋯evaluatorfold ticksread fixed.totalforcing depthEach step computes its total before the next beginsEvery step forces its own addition, one level deep, because the previous total is already a number. Reading the final total then needs no chain of earlier additions.1234stack limittotal[n]100000⋯evaluatorfold ticksread fixed.totalforcing depthIllustrative trace for n steps; the recorded run returns 100000.builtins.attrNames result?EvaluateExplore code
What does deepSeq evaluate in this counter?Another replacement callbackCodeacc: _: let next = { total = acc.total + 1; }; in builtins.deepSeq next nextDemandEvaluatesStill deferredseq next nextthe recordtotalseq next.total nexttotalnothingdeepSeq next nextevery field, including totalnothingdeepRecordFold: total from the deepSeq callbackdeepRecordFold?EvaluateExplore code
Which expression computes total without demanding metadata?metadata throws if it is demandedCodenext = { total = 1 + 1; metadata = throw "not needed for counting"; };Aseq next nextBseq next.total nextCdeepSeq next next
What do the two expressions evaluate?metadata throws if it is demandedCodenext = { total = 1 + 1; metadata = throw "not needed for counting"; };(builtins.seq next.total next).total?EvaluateExplore code(builtins.deepSeq next next).total?EvaluateExplore code
Compute the running total before returning the next record.countStepCodeacc: _: let total = acc.total + 1; in builtins.seq total { inherit total; }nixcon2026.bohinen.noExamples - captured evidence - reading - PDFssternenseemann: trampolining Nix (2022)