Skip to content

Commit 7d6374c

Browse files
committed
remove partial
1 parent 44caf6b commit 7d6374c

File tree

23 files changed

+88
-332
lines changed

23 files changed

+88
-332
lines changed

src/Init/Data/Iterators/Combinators/Monadic/Attach.lean

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ instance Attach.instIteratorLoop {α β : Type w} {m : Type w → Type w'} [Mona
9696
IteratorLoop (Attach α m P) m n :=
9797
.defaultImplementation
9898

99-
instance Attach.instIteratorLoopPartial {α β : Type w} {m : Type w → Type w'} [Monad m]
100-
{n : Type x → Type x'} [Monad n] {P : β → Prop} [Iterator α m β] :
101-
IteratorLoopPartial (Attach α m P) m n :=
102-
.defaultImplementation
103-
10499
instance {α β : Type w} {m : Type w → Type w'} [Monad m]
105100
{P : β → Prop} [Iterator α m β] [IteratorSize α m] :
106101
IteratorSize (Attach α m P) m where

src/Init/Data/Iterators/Combinators/Monadic/FilterMap.lean

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,10 @@ instance {α β γ : Type w} {m : Type w → Type w'}
222222
.defaultImplementation
223223

224224
instance FilterMap.instIteratorLoop {α β γ : Type w} {m : Type w → Type w'}
225-
{n : Type w → Type w''} {o : Type x → Type x'}
226-
[Monad n] [Monad o] [Iterator α m β] {lift : ⦃α : Type w⦄ → m α → n α}
227-
{f : β → PostconditionT n (Option γ)} [Finite α m] :
228-
IteratorLoop (FilterMap α m n lift f) n o :=
229-
.defaultImplementation
230-
231-
instance FilterMap.instIteratorLoopPartial {α β γ : Type w} {m : Type w → Type w'}
232225
{n : Type w → Type w''} {o : Type x → Type x'}
233226
[Monad n] [Monad o] [Iterator α m β] {lift : ⦃α : Type w⦄ → m α → n α}
234227
{f : β → PostconditionT n (Option γ)} :
235-
IteratorLoopPartial (FilterMap α m n lift f) n o :=
228+
IteratorLoop (FilterMap α m n lift f) n o :=
236229
.defaultImplementation
237230

238231
/--
@@ -259,13 +252,6 @@ instance Map.instIteratorLoop {α β γ : Type w} {m : Type w → Type w'}
259252
IteratorLoop (Map α m n lift f) n o :=
260253
.defaultImplementation
261254

262-
instance Map.instIteratorLoopPartial {α β γ : Type w} {m : Type w → Type w'}
263-
{n : Type w → Type w''} {o : Type x → Type x'} [Monad n] [Monad o] [Iterator α m β]
264-
{lift : ⦃α : Type w⦄ → m α → n α}
265-
{f : β → PostconditionT n γ} :
266-
IteratorLoopPartial (Map α m n lift f) n o :=
267-
.defaultImplementation
268-
269255
/--
270256
*Note: This is a very general combinator that requires an advanced understanding of monads, dependent
271257
types and termination proofs. The variants `map` and `mapM` are easier to use and sufficient

src/Init/Data/Iterators/Combinators/Monadic/FlatMap.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,4 @@ public instance Flatten.instIteratorLoop [Monad m] [Monad n] [Iterator α m (Ite
374374
[Iterator α₂ m β] : IteratorLoop (Flatten α α₂ β m) m n :=
375375
.defaultImplementation
376376

377-
public instance Flatten.instIteratorLoopPartial [Monad m] [Monad n] [Iterator α m (IterM (α := α₂) m β)]
378-
[Iterator α₂ m β] : IteratorLoopPartial (Flatten α α₂ β m) m n :=
379-
.defaultImplementation
380-
381377
end Std.Iterators

src/Init/Data/Iterators/Combinators/Monadic/ULift.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ instance Types.ULiftIterator.instIteratorLoop {o : Type x → Type x'} [Monad n]
128128
IteratorLoop (ULiftIterator α m n β lift) n o :=
129129
.defaultImplementation
130130

131-
instance Types.ULiftIterator.instIteratorLoopPartial {o : Type x → Type x'} [Monad n] [Monad o] [Iterator α m β] :
132-
IteratorLoopPartial (ULiftIterator α m n β lift) n o :=
133-
.defaultImplementation
134-
135131
instance Types.ULiftIterator.instIteratorCollect [Monad n] [Monad o] [Iterator α m β] :
136132
IteratorCollect (ULiftIterator α m n β lift) n o :=
137133
.defaultImplementation

src/Init/Data/Iterators/Consumers/Loop.lean

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ instance (α : Type w) (β : Type w) (n : Type x → Type x') [Monad n]
4848

4949
@[always_inline, inline]
5050
def Iter.Partial.instForIn' {α : Type w} {β : Type w} {n : Type x → Type x'} [Monad n]
51-
[Iterator α Id β] [IteratorLoopPartial α Id n] :
51+
[Iterator α Id β] [IteratorLoop α Id n] :
5252
ForIn' n (Iter.Partial (α := α) β) β ⟨fun it out => it.it.IsPlausibleIndirectOutput out⟩ where
5353
forIn' it init f :=
54-
IteratorLoopPartial.forInPartial (α := α) (m := Id) (n := n) (fun _ _ f c => f c.run)
54+
IteratorLoop.forIn (α := α) (m := Id) (n := n) (fun _ _ f c => f c.run) _
5555
it.it.toIterM init
5656
fun out h acc =>
5757
f out (Iter.isPlausibleIndirectOutput_iff_isPlausibleIndirectOutput_toIterM.mpr h) acc
5858

5959
instance (α : Type w) (β : Type w) (n : Type x → Type x') [Monad n]
60-
[Iterator α Id β] [IteratorLoopPartial α Id n] :
60+
[Iterator α Id β] [IteratorLoop α Id n] :
6161
ForIn n (Iter.Partial (α := α) β) β :=
6262
haveI : ForIn' n (Iter.Partial (α := α) β) β _ := Iter.Partial.instForIn'
6363
instForInOfForIn'
@@ -68,7 +68,7 @@ instance {m : Type x → Type x'}
6868
forM it f := forIn it PUnit.unit (fun out _ => do f out; return .yield .unit)
6969

7070
instance {m : Type x → Type x'}
71-
{α : Type w} {β : Type w} [Iterator α Id β] [IteratorLoopPartial α Id m] :
71+
{α : Type w} {β : Type w} [Iterator α Id β] [IteratorLoop α Id m] :
7272
ForM m (Iter.Partial (α := α) β) β where
7373
forM it f := forIn it PUnit.unit (fun out _ => do f out; return .yield .unit)
7474

@@ -77,11 +77,6 @@ Folds a monadic function over an iterator from the left, accumulating a value st
7777
The accumulated value is combined with the each element of the list in order, using `f`.
7878
7979
It is equivalent to `it.toList.foldlM`.
80-
81-
This function requires a `Finite` instance proving that the iterator will finish after a finite
82-
number of steps. If the iterator is not finite or such an instance is not available, consider using
83-
`it.allowNontermination.foldM` instead of `it.foldM`. However, it is not possible to formally
84-
verify the behavior of the partial variant.
8580
-/
8681
@[always_inline, inline]
8782
def Iter.foldM {m : Type x → Type x'} [Monad m]
@@ -96,13 +91,12 @@ The accumulated value is combined with the each element of the list in order, us
9691
9792
It is equivalent to `it.toList.foldlM`.
9893
99-
This is a partial, potentially nonterminating, function. It is not possible to formally verify
100-
its behavior. If the iterator has a `Finite` instance, consider using `IterM.foldM` instead.
94+
This function is deprecated. Instead of `it.allowNontermination.foldM`, use `it.foldM`.
10195
-/
10296
@[always_inline, inline]
10397
def Iter.Partial.foldM {m : Type x → Type x'} [Monad m]
10498
{α : Type w} {β : Type w} {γ : Type x} [Iterator α Id β]
105-
[IteratorLoopPartial α Id m] (f : γ → β → m γ)
99+
[IteratorLoop α Id m] (f : γ → β → m γ)
106100
(init : γ) (it : Iter.Partial (α := α) β) : m γ :=
107101
ForIn.forIn it init (fun x acc => ForInStep.yield <$> f acc x)
108102

@@ -111,11 +105,6 @@ Folds a function over an iterator from the left, accumulating a value starting w
111105
The accumulated value is combined with the each element of the list in order, using `f`.
112106
113107
It is equivalent to `it.toList.foldl`.
114-
115-
This function requires a `Finite` instance proving that the iterator will finish after a finite
116-
number of steps. If the iterator is not finite or such an instance is not available, consider using
117-
`it.allowNontermination.fold` instead of `it.fold`. However, it is not possible to formally
118-
verify the behavior of the partial variant.
119108
-/
120109
@[always_inline, inline]
121110
def Iter.fold {α : Type w} {β : Type w} {γ : Type x} [Iterator α Id β]
@@ -129,12 +118,11 @@ The accumulated value is combined with the each element of the list in order, us
129118
130119
It is equivalent to `it.toList.foldl`.
131120
132-
This is a partial, potentially nonterminating, function. It is not possible to formally verify
133-
its behavior. If the iterator has a `Finite` instance, consider using `IterM.fold` instead.
121+
This function is deprecated. Instead of `it.allowNontermination.fold`, use `it.fold`.
134122
-/
135123
@[always_inline, inline]
136124
def Iter.Partial.fold {α : Type w} {β : Type w} {γ : Type x} [Iterator α Id β]
137-
[IteratorLoopPartial α Id Id] (f : γ → β → γ)
125+
[IteratorLoop α Id Id] (f : γ → β → γ)
138126
(init : γ) (it : Iter.Partial (α := α) β) : γ :=
139127
ForIn.forIn (m := Id) it init (fun x acc => ForInStep.yield (f acc x))
140128

@@ -211,56 +199,53 @@ def Iter.findSomeM? {α β : Type w} {γ : Type x} {m : Type x → Type w'} [Mon
211199
| none => return .yield none
212200
| some fx => return .done (some fx))
213201

214-
@[inline]
202+
@[inline, deprecated Iter.findSomeM? (since := "2025-10-21")]
215203
def Iter.Partial.findSomeM? {α β : Type w} {γ : Type x} {m : Type x → Type w'} [Monad m]
216-
[Iterator α Id β] [IteratorLoopPartial α Id m] (it : Iter.Partial (α := α) β)
204+
[Iterator α Id β] [IteratorLoop α Id m] (it : Iter.Partial (α := α) β)
217205
(f : β → m (Option γ)) :
218206
m (Option γ) :=
219-
ForIn.forIn it none (fun x _ => do
220-
match ← f x with
221-
| none => return .yield none
222-
| some fx => return .done (some fx))
207+
it.it.findSomeM? f
223208

224209
@[inline]
225210
def Iter.findSome? {α β : Type w} {γ : Type x} [Iterator α Id β]
226211
[IteratorLoop α Id Id] (it : Iter (α := α) β) (f : β → Option γ) :
227212
Option γ :=
228213
Id.run (it.findSomeM? (pure <| f ·))
229214

230-
@[inline]
215+
@[inline, deprecated Iter.findSome? (since := "2025-10-21")]
231216
def Iter.Partial.findSome? {α β : Type w} {γ : Type x} [Iterator α Id β]
232-
[IteratorLoopPartial α Id Id] (it : Iter.Partial (α := α) β) (f : β → Option γ) :
217+
[IteratorLoop α Id Id] (it : Iter.Partial (α := α) β) (f : β → Option γ) :
233218
Option γ :=
234-
Id.run (it.findSomeM? (pure <| f ·))
219+
it.it.findSome? f
235220

236221
@[inline]
237222
def Iter.findM? {α β : Type w} {m : Type w → Type w'} [Monad m] [Iterator α Id β]
238223
[IteratorLoop α Id m] (it : Iter (α := α) β) (f : β → m (ULift Bool)) :
239224
m (Option β) :=
240225
it.findSomeM? (fun x => return if (← f x).down then some x else none)
241226

242-
@[inline]
227+
@[inline, deprecated Iter.findM? (since := "2025-10-21")]
243228
def Iter.Partial.findM? {α β : Type w} {m : Type w → Type w'} [Monad m] [Iterator α Id β]
244-
[IteratorLoopPartial α Id m] (it : Iter.Partial (α := α) β) (f : β → m (ULift Bool)) :
229+
[IteratorLoop α Id m] (it : Iter.Partial (α := α) β) (f : β → m (ULift Bool)) :
245230
m (Option β) :=
246-
it.findSomeM? (fun x => return if (← f x).down then some x else none)
231+
it.it.findM? f
247232

248233
@[inline]
249234
def Iter.find? {α β : Type w} [Iterator α Id β] [IteratorLoop α Id Id]
250235
(it : Iter (α := α) β) (f : β → Bool) : Option β :=
251236
Id.run (it.findM? (pure <| .up <| f ·))
252237

253-
@[inline]
254-
def Iter.Partial.find? {α β : Type w} [Iterator α Id β] [IteratorLoopPartial α Id Id]
238+
@[inline, deprecated Iter.find? (since := "2025-10-21")]
239+
def Iter.Partial.find? {α β : Type w} [Iterator α Id β] [IteratorLoop α Id Id]
255240
(it : Iter.Partial (α := α) β) (f : β → Bool) : Option β :=
256-
Id.run (it.findM? (pure <| .up <| f ·))
241+
it.it.find? f
257242

258-
@[always_inline, inline, expose, inherit_doc IterM.size]
243+
@[always_inline, expose, inherit_doc IterM.size]
259244
def Iter.size {α : Type w} {β : Type w} [Iterator α Id β] [IteratorSize α Id]
260245
(it : Iter (α := α) β) : Nat :=
261246
(IteratorSize.size it.toIterM).run.down
262247

263-
@[always_inline, inline, inherit_doc IterM.Partial.size]
248+
@[always_inline, inherit_doc IterM.Partial.size]
264249
def Iter.Partial.size {α : Type w} {β : Type w} [Iterator α Id β] [IteratorSizePartial α Id]
265250
(it : Iter (α := α) β) : Nat :=
266251
(IteratorSizePartial.size it.toIterM).run.down

0 commit comments

Comments
 (0)