Skip to content

Commit 6ec4f85

Browse files
committed
solve defeq abuse in the iterator library
1 parent 6a31d83 commit 6ec4f85

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/Std/Data/Iterators/Consumers/Collect.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,31 @@ namespace Std.Iterators
2727
@[always_inline, inline, inherit_doc IterM.toArray]
2828
def Iter.toArray {α : Type w} {β : Type w}
2929
[Iterator α Id β] [Finite α Id] [IteratorCollect α Id] (it : Iter (α := α) β) : Array β :=
30-
it.toIterM.toArray
30+
it.toIterM.toArray.run
3131

3232
@[always_inline, inline, inherit_doc IterM.Partial.toArray]
3333
def Iter.Partial.toArray {α : Type w} {β : Type w}
3434
[Iterator α Id β] [IteratorCollectPartial α Id] (it : Iter.Partial (α := α) β) : Array β :=
35-
it.it.toIterM.allowNontermination.toArray
35+
it.it.toIterM.allowNontermination.toArray.run
3636

3737
@[always_inline, inline, inherit_doc IterM.toListRev]
3838
def Iter.toListRev {α : Type w} {β : Type w}
3939
[Iterator α Id β] [Finite α Id] (it : Iter (α := α) β) : List β :=
40-
it.toIterM.toListRev
40+
it.toIterM.toListRev.run
4141

4242
@[always_inline, inline, inherit_doc IterM.Partial.toListRev]
4343
def Iter.Partial.toListRev {α : Type w} {β : Type w}
4444
[Iterator α Id β] (it : Iter.Partial (α := α) β) : List β :=
45-
it.it.toIterM.allowNontermination.toListRev
45+
it.it.toIterM.allowNontermination.toListRev.run
4646

4747
@[always_inline, inline, inherit_doc IterM.toList]
4848
def Iter.toList {α : Type w} {β : Type w}
4949
[Iterator α Id β] [Finite α Id] [IteratorCollect α Id] (it : Iter (α := α) β) : List β :=
50-
it.toIterM.toList
50+
it.toIterM.toList.run
5151

5252
@[always_inline, inline, inherit_doc IterM.Partial.toList]
5353
def Iter.Partial.toList {α : Type w} {β : Type w}
5454
[Iterator α Id β] [IteratorCollectPartial α Id] (it : Iter.Partial (α := α) β) : List β :=
55-
it.it.toIterM.allowNontermination.toList
55+
it.it.toIterM.allowNontermination.toList.run
5656

5757
end Std.Iterators

src/Std/Data/Iterators/Lemmas/Consumers/Collect.lean

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,55 @@ namespace Std.Iterators
1313

1414
theorem Iter.toArray_eq_toArray_toIterM {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id]
1515
[LawfulIteratorCollect α Id] {it : Iter (α := α) β} :
16-
it.toArray = it.toIterM.toArray :=
16+
it.toArray = it.toIterM.toArray.run :=
1717
rfl
1818

1919
theorem Iter.toList_eq_toList_toIterM {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id]
2020
[LawfulIteratorCollect α Id] {it : Iter (α := α) β} :
21-
it.toList = it.toIterM.toList :=
21+
it.toList = it.toIterM.toList.run :=
2222
rfl
2323

2424
theorem Iter.toListRev_eq_toListRev_toIterM {α β} [Iterator α Id β] [Finite α Id]
2525
{it : Iter (α := α) β} :
26-
it.toListRev = it.toIterM.toListRev :=
26+
it.toListRev = it.toIterM.toListRev.run :=
2727
rfl
2828

2929
@[simp]
3030
theorem IterM.toList_toIter {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id]
3131
{it : IterM (α := α) Id β} :
32-
it.toIter.toList = it.toList :=
32+
it.toIter.toList = it.toList.run :=
3333
rfl
3434

3535
@[simp]
3636
theorem IterM.toListRev_toIter {α β} [Iterator α Id β] [Finite α Id]
3737
{it : IterM (α := α) Id β} :
38-
it.toIter.toListRev = it.toListRev :=
38+
it.toIter.toListRev = it.toListRev.run :=
3939
rfl
4040

4141
theorem Iter.toList_toArray {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id]
4242
[LawfulIteratorCollect α Id] {it : Iter (α := α) β} :
4343
it.toArray.toList = it.toList := by
44-
simp only [toArray_eq_toArray_toIterM, toList_eq_toList_toIterM, ← IterM.toList_toArray]
45-
rfl -- FIXME: defeq abuse of `Id`.
44+
simp [toArray_eq_toArray_toIterM, toList_eq_toList_toIterM, ← IterM.toList_toArray]
4645

4746
theorem Iter.toArray_toList {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id]
4847
[LawfulIteratorCollect α Id] {it : Iter (α := α) β} :
4948
it.toList.toArray = it.toArray := by
50-
simp only [toArray_eq_toArray_toIterM, toList_eq_toList_toIterM, ← IterM.toArray_toList]
51-
rfl -- FIXME: defeq abuse of `Id`.
49+
simp [toArray_eq_toArray_toIterM, toList_eq_toList_toIterM, ← IterM.toArray_toList]
50+
5251
theorem Iter.toListRev_eq {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id]
5352
[LawfulIteratorCollect α Id] {it : Iter (α := α) β} :
5453
it.toListRev = it.toList.reverse := by
5554
simp [Iter.toListRev_eq_toListRev_toIterM, Iter.toList_eq_toList_toIterM, IterM.toListRev_eq]
56-
rfl -- FIXME: defeq abuse of
5755

58-
set_option linter.deprecated false in -- FIXME: defeq abuse of `Id`.
5956
theorem Iter.toArray_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id]
6057
[LawfulIteratorCollect α Id] {it : Iter (α := α) β} :
6158
it.toArray = match it.step with
6259
| .yield it' out _ => #[out] ++ it'.toArray
6360
| .skip it' _ => it'.toArray
6461
| .done _ => #[] := by
6562
simp only [Iter.toArray_eq_toArray_toIterM, Iter.step]
66-
rw [IterM.toArray_eq_match_step]
67-
simp only [Id.run_map, Id.pure_eq, Id.bind_eq, Id.run]
68-
generalize it.toIterM.step = step
63+
rw [IterM.toArray_eq_match_step, Id.run_bind]
64+
generalize it.toIterM.step.run = step
6965
cases step using PlausibleIterStep.casesOn <;> simp
7066

7167
theorem Iter.toList_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id]
@@ -77,15 +73,13 @@ theorem Iter.toList_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [It
7773
rw [← Iter.toList_toArray, Iter.toArray_eq_match_step]
7874
split <;> simp [Iter.toList_toArray]
7975

80-
set_option linter.deprecated false in -- FIXME: defeq abuse of `Id`.
8176
theorem Iter.toListRev_eq_match_step {α β} [Iterator α Id β] [Finite α Id] {it : Iter (α := α) β} :
8277
it.toListRev = match it.step with
8378
| .yield it' out _ => it'.toListRev ++ [out]
8479
| .skip it' _ => it'.toListRev
8580
| .done _ => [] := by
86-
rw [Iter.toListRev_eq_toListRev_toIterM, IterM.toListRev_eq_match_step, Iter.step]
87-
simp only [Id.map_eq, Id.pure_eq, Id.bind_eq, Id.run]
88-
generalize it.toIterM.step = step
81+
rw [Iter.toListRev_eq_toListRev_toIterM, IterM.toListRev_eq_match_step, Iter.step, Id.run_bind]
82+
generalize it.toIterM.step.run = step
8983
cases step using PlausibleIterStep.casesOn <;> simp
9084

9185
theorem Iter.getElem?_toList_eq_atIdxSlow? {α β}

0 commit comments

Comments
 (0)