@@ -4,20 +4,20 @@ import Iterator.Basic
44def IterM.DefaultConsumers.forIn {m : Type w → Type w'} {n : Type w → Type w''} [Monad n] [MonadLiftT m n]
55 {α : Type w} {β : Type v} {γ : Type w}
66 [Iterator α m β] [Finite α m]
7- (it : IterM (α := α) m β) (init : γ) {successor_of : β → γ → γ → Prop }
8- (f : (b : β) → (c : γ) → n (Subtype fun s : ForInStep γ => successor_of b c s.value )) : n γ := do
7+ (it : IterM (α := α) m β) (init : γ)
8+ (f : (b : β) → (c : γ) → n (ForInStep γ)) : n γ := do
99 match (← it.stepH).inflate with
1010 | .yield it' out _ =>
1111 match ← f out init with
12- | ⟨ .yield c, _⟩ => IterM.DefaultConsumers.forIn it' c f
13- | ⟨ .done c, _⟩ => return c
12+ | .yield c => IterM.DefaultConsumers.forIn it' c f
13+ | .done c => return c
1414 | .skip it' _ => IterM.DefaultConsumers.forIn it' init f
1515 | .done _ => return init
1616termination_by it.finitelyManySteps
1717
1818class IteratorFor (α : Type w) (m : Type w → Type w') {β : Type v} [Iterator α m β] (n : Type w → Type w'') where
19- forIn : ∀ {γ : Type w}, IterM (α := α) m β → γ → {successor_of : β → γ → γ → Prop } →
20- ((b : β) → (c : γ) → n (Subtype fun s : ForInStep γ => successor_of b c s.value )) →
19+ forIn : ∀ {γ : Type w}, IterM (α := α) m β → γ →
20+ ((b : β) → (c : γ) → n (ForInStep γ)) →
2121 n γ
2222
2323class LawfulIteratorFor (α : Type w) (m : Type w → Type w') (n : Type w → Type w'')
@@ -38,15 +38,13 @@ instance (α : Type w) (m : Type w → Type w') (n : Type w → Type w')
3838 ⟨fun _ => rfl⟩
3939
4040instance {m : Type w → Type w'} {n : Type w → Type w''}
41- {α : Type w} {β : Type v} [Iterator α m β] [Finite α m] [ IteratorFor α m n] :
41+ {α : Type w} {β : Type v} [Iterator α m β] [IteratorFor α m n] :
4242 ForIn n (IterM (α := α) m β) β where
43- forIn it init stepper := IteratorFor.forIn it init
44- (successor_of := fun _ _ _ => True)
45- (fun b c => (⟨·, True.intro⟩) <$> stepper b c)
43+ forIn := IteratorFor.forIn
4644
4745@[specialize]
4846def IterM.foldM {m : Type w → Type w'} {n : Type w → Type w'} [Monad n]
49- {α : Type w} {β : Type v} {γ : Type w} [Iterator α m β] [Finite α m] [ IteratorFor α m n]
47+ {α : Type w} {β : Type v} {γ : Type w} [Iterator α m β] [IteratorFor α m n]
5048 (f : γ → β → n γ) (init : γ) (it : IterM (α := α) m β) : n γ :=
5149 ForIn.forIn it init (fun x acc => ForInStep.yield <$> f acc x)
5250
0 commit comments