lean4-htt/tests/elab/lazylistThunk.lean
Garmelon 08eb78a5b2
chore: switch to new test/bench suite (#12590)
This PR sets up the new integrated test/bench suite. It then migrates
all benchmarks and some related tests to the new suite. There's also
some documentation and some linting.

For now, a lot of the old tests are left alone so this PR doesn't become
even larger than it already is. Eventually, all tests should be migrated
to the new suite though so there isn't a confusing mix of two systems.
2026-02-25 13:51:53 +00:00

43 lines
1.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

inductive LazyList (α : Type u)
| nil : LazyList α
| cons (hd : α) (tl : LazyList α) : LazyList α
| delayed (t : Thunk (LazyList α)) : LazyList α
deriving Inhabited
namespace LazyList
@[inline] protected def pure (a : α) : LazyList α :=
cons a nil
/-
Length of a list is number of actual elements
in the list, ignoring delays
-/
@[simp] def length : LazyList α → Nat
| nil => 0
| cons _ as => length as + 1
| delayed as => length as.get
@[simp] def toList : LazyList α → List α
| nil => []
| cons a as => a :: toList as
| delayed as => toList as.get
theorem length_toList (l : LazyList α) : l.toList.length = l.length := by
match l with
| nil => simp [length_toList]
| cons a as => simp [length_toList as]
| delayed as => simp [length_toList as.get]
def force : LazyList α → Option (α × LazyList α)
| delayed as => force as.get
| nil => none
| cons a as => some (a,as)
theorem toList_force_none (l : LazyList α) : force l = none ↔ l.toList = List.nil := by
match l with
| nil => simp [force]
| delayed as => simp [force, toList_force_none as.get]
| cons a as => simp [force, toList_force_none as]
end LazyList