From 9f485affc2bef9acf2fdcf9d754377ed5befd909 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 17:45:03 +0000 Subject: [PATCH 1/2] Initial plan From ee6132e81ce2807b0371100d6490a9b80115330e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 17:52:20 +0000 Subject: [PATCH 2/2] Fix consLazy laziness: use mutable in test and prevent tail forcing on head access Co-authored-by: gdziadkiewicz <8547855+gdziadkiewicz@users.noreply.github.com> --- src/FSharpx.Collections/LazyList.fs | 2 +- tests/FSharpx.Collections.Tests/LazyListTests.fs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/FSharpx.Collections/LazyList.fs b/src/FSharpx.Collections/LazyList.fs index fbf4511f..b4d4500f 100644 --- a/src/FSharpx.Collections/LazyList.fs +++ b/src/FSharpx.Collections/LazyList.fs @@ -115,7 +115,7 @@ module LazyList = lzy(fun () -> (consc x (lzy(fun () -> (force(l())))))) let consLazy x (l: Lazy>) = - lzy(fun () -> consc x l.Value) + notlazy(CellCons(x, lzy(fun () -> force l.Value))) let uncons(s: LazyList<'T>) = s.Uncons diff --git a/tests/FSharpx.Collections.Tests/LazyListTests.fs b/tests/FSharpx.Collections.Tests/LazyListTests.fs index 8648c533..e197ba59 100644 --- a/tests/FSharpx.Collections.Tests/LazyListTests.fs +++ b/tests/FSharpx.Collections.Tests/LazyListTests.fs @@ -329,7 +329,17 @@ module LazyList = test "consLazy lazy divergence" { // tail is not evaluated unless the tail is consumed - Expect.isTrue "consLazy divergence" (let _ = LazyList.consLazy 1 (lazy (failwith "diverge")) in true) + let mutable tailForced = false + + let tail = + lazy + (tailForced <- true + LazyList.ofList [ 2; 3 ]) + + let ll = LazyList.consLazy 1 tail + Expect.isFalse "consLazy divergence: construction should not force the tail" tailForced + let _ = LazyList.head ll + Expect.isFalse "consLazy divergence: head should not force the tail" tailForced } test "consLazy infinite" {