Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 856c852

Browse files
committed
allowNontermination example
1 parent bd34e6f commit 856c852

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Iterator/Examples.lean

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,12 @@ info: [time("13:47:35.833520000"),
153153
-/
154154
-- #eval timestamps 5
155155

156-
-- Note: The following wouldn't work because the `Productive` instance for `.mapM` is still missing
157-
/-
158-
def timestamps (n : Nat) : IO (List Std.Time.PlainTime) := do
159-
IterM.unfold 0 (fun _ => 0) IO |>.take n |>.mapM (fun _ => Std.Time.PlainTime.now) |>.toList
160-
-/
156+
-- Note:
157+
-- The following terminates but we can't prove it because the `Productive` instance for `.mapM` is still missing.
158+
-- Hence we need to use the `partial` variant of `toList` -- it might not terminate and we
159+
-- can't prove anything about this function.
160+
def timestamps' (n : Nat) : IO (List Std.Time.PlainTime) := do
161+
IterM.unfold IO 0 (fun _ => 0) |>.mapM (fun _ => Std.Time.PlainTime.now) |>.take n |>.allowNontermination.toList
161162

162163
-- This example demonstrates that chained `mapM` calls are executed in a different order than with `List.mapM`.
163164
def chainedMapM (l : List Nat) : IO Unit :=

0 commit comments

Comments
 (0)