mirror of
https://github.com/NixOS/nix
synced 2025-07-07 10:11:47 +02:00
primops: make nature of foldl' strictness clearer
* Clarify the documentation of foldl': That the arguments are forced before application (?) of `op` is necessarily true. What is important to stress is that we force every application of `op`, even when the value turns out to be unused. * Move the example before the comment about strictness to make it less confusing: It is a general example and doesn't really showcase anything about foldl' strictness. * Add test cases which nail down aspects of foldl' strictness: * The initial accumulator value is not forced unconditionally. * Applications of op are forced. * The list elements are not forced unconditionally.
This commit is contained in:
parent
ac0fb38e8a
commit
d0f2da214b
6 changed files with 25 additions and 3 deletions
9
tests/lang/eval-okay-foldlStrict-lazy-elements.nix
Normal file
9
tests/lang/eval-okay-foldlStrict-lazy-elements.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Tests that the rhs argument of op is not forced unconditionally
|
||||
let
|
||||
lst = builtins.foldl'
|
||||
(acc: x: acc ++ [ x ])
|
||||
[ ]
|
||||
[ 42 (throw "this shouldn't be evaluated") ];
|
||||
in
|
||||
|
||||
builtins.head lst
|
Loading…
Add table
Add a link
Reference in a new issue