lean4-htt/src/Std/Data/Iterators/Producers/Monadic/Empty.lean
Paul Reichert f58999a7a6
refactor: use Shrink stub in the iterator framework (#10725)
This PR introduces a no-op version of `Shrink`, a type that should allow
shrinking small types into smaller universes given a proof that the type
is small enough, and uses it in the iterator library. Because this type
would require special compiler support, the current version is just a
wrapper around the inner type so that the wrapper is equivalent, but not
definitionally equivalent.

While `Shrink` is unable to shrink universes right now, but introducing
it now will allow us to generalize the universes in the iterator library
with fewer breaking changes as soon as an actual `Shrink` is possible.
2025-10-14 10:22:14 +00:00

77 lines
2.1 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.

/-
Copyright (c) 2025 Lean FRO, LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul Reichert
-/
module
prelude
public import Init.Data.Iterators.Consumers.Collect
public import Init.Data.Iterators.Consumers.Loop
public import Init.Data.Iterators.Internal.Termination
@[expose] public section
/-!
This file provides an empty iterator.
-/
namespace Std.Iterators
variable {m : Type w → Type w'} {β : Type w}
/--
The internal state of the `IterM.empty` iterator.
-/
structure Empty (m : Type w → Type w') (β : Type w) : Type w where
/--
Returns an iterator that terminates immediately.
**Termination properties:**
* `Finite` instance: always
* `Productive` instance: always
-/
@[always_inline, inline]
def IterM.empty (m : Type w → Type w') (β : Type w) :=
toIterM (Empty.mk (m := m) (β := β)) m β
def Empty.PlausibleStep (_ : IterM (α := Empty m β) m β)
(step : IterStep (IterM (α := Empty m β) m β) β) : Prop :=
step = .done
instance Empty.instIterator [Monad m] : Iterator (Empty m β) m β where
IsPlausibleStep := Empty.PlausibleStep
step _ := return .deflate (.done rfl)
private def Empty.instFinitenessRelation [Monad m] :
FinitenessRelation (Empty m β) m where
rel := emptyRelation
wf := emptyWf.wf
subrelation {it it'} h := by
obtain ⟨step, h, h'⟩ := h
cases h'
cases h
instance Empty.instFinite [Monad m] : Finite (Empty m β) m := by
exact Finite.of_finitenessRelation instFinitenessRelation
instance Empty.instIteratorCollect {n : Type w → Type w''} [Monad m] [Monad n] :
IteratorCollect (Empty m β) m n :=
.defaultImplementation
instance Empty.instIteratorCollectPartial {n : Type w → Type w''} [Monad m] [Monad n] :
IteratorCollectPartial (Empty m β) m n :=
.defaultImplementation
instance Empty.instIteratorLoop {n : Type x → Type x'} [Monad m] [Monad n] :
IteratorLoop (Empty m β) m n :=
.defaultImplementation
instance Empty.instIteratorLoopPartial {n : Type x → Type x'} [Monad m] [Monad n] :
IteratorLoopPartial (Empty m β) m n :=
.defaultImplementation
end Std.Iterators