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" {