@@ -115,27 +115,27 @@ def Iter.toIterM {α : Type w} {β : Type w} (it : Iter (α := α) β) : IterM (
115115/--
116116Converts a monadic iterator (`IterM Id β`) over `Id` into a pure iterator (`Iter β`).
117117-/
118- def IterM.toPureIter {α : Type w} {β : Type w} (it : IterM (α := α) Id β) : Iter (α := α) β :=
118+ def IterM.toIter {α : Type w} {β : Type w} (it : IterM (α := α) Id β) : Iter (α := α) β :=
119119 ⟨it.internalState⟩
120120
121121@[simp]
122- theorem Iter.toPureIter_toIterM {α : Type w} {β : Type w} (it : Iter (α := α) β) :
123- it.toIterM.toPureIter = it :=
122+ theorem Iter.toIter_toIterM {α : Type w} {β : Type w} (it : Iter (α := α) β) :
123+ it.toIterM.toIter = it :=
124124 rfl
125125
126126@[simp]
127- theorem Iter.toPureIter_comp_toIterM {α : Type w} {β : Type w} :
128- IterM.toPureIter ∘ Iter.toIterM (α := α) (β := β) = id :=
127+ theorem Iter.toIter_comp_toIterM {α : Type w} {β : Type w} :
128+ IterM.toIter ∘ Iter.toIterM (α := α) (β := β) = id :=
129129 rfl
130130
131131@[simp]
132- theorem Iter.toIterM_toPureIter {α : Type w} {β : Type w} (it : IterM (α := α) Id β) :
133- it.toPureIter .toIterM = it :=
132+ theorem Iter.toIterM_toIter {α : Type w} {β : Type w} (it : IterM (α := α) Id β) :
133+ it.toIter .toIterM = it :=
134134 rfl
135135
136136@[simp]
137- theorem Iter.toIterM_comp_toPureIter {α : Type w} {β : Type w} :
138- Iter.toIterM ∘ IterM.toPureIter (α := α) (β := β) = id :=
137+ theorem Iter.toIterM_comp_toIter {α : Type w} {β : Type w} :
138+ Iter.toIterM ∘ IterM.toIter (α := α) (β := β) = id :=
139139 rfl
140140
141141section IterStep
@@ -184,8 +184,8 @@ def IterStep.mapIterator {α' : Type u'} (f : α → α') : IterStep α β → I
184184 | .done => .done
185185
186186@[simp]
187- theorem IterStep.mapIterator_mapIterator {α' : Type u'} {f : α → α'} {g : α' → α }
188- {step : IterStep α β} :
187+ theorem IterStep.mapIterator_mapIterator {α' : Type u'} {α'' : Type u'' }
188+ {f : α → α'} {g : α' → α''} { step : IterStep α β} :
189189 (step.mapIterator f).mapIterator g = step.mapIterator (g ∘ f) := by
190190 cases step <;> rfl
191191
@@ -229,35 +229,18 @@ def PlausibleIterStep.done {IsPlausibleStep : IterStep α β → Prop}
229229 ⟨.done, h⟩
230230
231231/--
232- An inductive type that makes it easier to apply the `cases` tactic to a
233- `PlausibleIterStep`. See `PlausibleIterStep.casesHelper` for more information.
232+ A more convenient `cases` eliminator for `PlausibleIterStep`.
234233-/
235- inductive PlausibleIterStep.CasesHelper {IsPlausibleStep : IterStep α β → Prop } :
236- PlausibleIterStep IsPlausibleStep → Type _ where
237- | yield (it' out h) : CasesHelper ⟨.yield it' out, h⟩
238- | skip (it' h) : CasesHelper ⟨.skip it', h⟩
239- | done (h) : CasesHelper ⟨.done, h⟩
240-
241- /--
242- Because `PlausibleIterStep` is a subtype of `IterStep`, it is tedious to use
243- the `cases` tactic:
244-
245- ```lean
246- obtain ⟨step, h⟩ := step
247- cases step
248- ```
249-
250- Using `casesHelper`, the case distinction can be done more ergonomically.
251-
252- ```lean
253- cases step.casesHelper
254- ```
255- -/
256- def PlausibleIterStep.casesHelper {IsPlausibleStep : IterStep α β → Prop } :
257- (step : PlausibleIterStep IsPlausibleStep) → PlausibleIterStep.CasesHelper step
258- | .yield it' out h => .yield it' out h
259- | .skip it' h => .skip it' h
260- | .done h => .done h
234+ @[elab_as_elim, cases_eliminator]
235+ abbrev PlausibleIterStep.casesOn {IsPlausibleStep : IterStep α β → Prop }
236+ {motive : PlausibleIterStep IsPlausibleStep → Sort x} (s : PlausibleIterStep IsPlausibleStep)
237+ (yield : ∀ it' out h, motive ⟨.yield it' out, h⟩)
238+ (skip : ∀ it' h, motive ⟨.skip it', h⟩)
239+ (done : ∀ h, motive ⟨.done, h⟩) : motive s :=
240+ match s with
241+ | .yield it' out h => yield it' out h
242+ | .skip it' h => skip it' h
243+ | .done h => done h
261244
262245end IterStep
263246
@@ -374,17 +357,17 @@ Converts an `IterM.Step` into an `Iter.Step`.
374357-/
375358@[always_inline, inline]
376359def IterM.Step.toPure {α : Type w} {β : Type w} [Iterator α Id β] {it : IterM (α := α) Id β}
377- (step : it.Step) : it.toPureIter .Step :=
378- ⟨step.val.mapIterator IterM.toPureIter , (by simp [Iter.IsPlausibleStep, step.property])⟩
360+ (step : it.Step) : it.toIter .Step :=
361+ ⟨step.val.mapIterator IterM.toIter , (by simp [Iter.IsPlausibleStep, step.property])⟩
379362
380363@[simp]
381364theorem IterM.Step.toPure_yield {α β : Type w} [Iterator α Id β] {it : IterM (α := α) Id β}
382- {it' out h} : IterM.Step.toPure (⟨.yield it' out, h⟩ : it.Step) = .yield it'.toPureIter out h :=
365+ {it' out h} : IterM.Step.toPure (⟨.yield it' out, h⟩ : it.Step) = .yield it'.toIter out h :=
383366 rfl
384367
385368@[simp]
386369theorem IterM.Step.toPure_skip {α β : Type w} [Iterator α Id β] {it : IterM (α := α) Id β}
387- {it' h} : IterM.Step.toPure (⟨.skip it', h⟩ : it.Step) = .skip it'.toPureIter h :=
370+ {it' h} : IterM.Step.toPure (⟨.skip it', h⟩ : it.Step) = .skip it'.toIter h :=
388371 rfl
389372
390373@[simp]
0 commit comments