Skip to content

Commit b52a1c3

Browse files
authored
Merge branch 'leanprover:main' into main
2 parents 12c5f7e + f22a241 commit b52a1c3

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

Cslib/Foundations/Control/Monad/Free/Effects.lean

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ The canonical interpreter `toStateM` derived from `liftM` agrees with the hand-w
100100
recursive interpreter `run` for `FreeState`.
101101
-/
102102
@[simp]
103-
theorem run_toStateM {α : Type u} (comp : FreeState σ α) :
104-
(toStateM comp).run = run comp := by
105-
ext s₀ : 1
103+
theorem run_toStateM {α : Type u} (comp : FreeState σ α) (s₀ : σ) :
104+
(toStateM comp).run s₀ = pure (run comp s₀) := by
106105
induction comp generalizing s₀ with
107106
| pure a => rfl
108107
| liftBind op cont ih =>
@@ -123,11 +122,10 @@ lemma run_set (s' : σ) (k : PUnit → FreeState σ α) (s₀ : σ) :
123122
/-- Run a state computation, returning only the result. -/
124123
def run' (c : FreeState σ α) (s₀ : σ) : α := (run c s₀).1
125124

126-
@[simp]
127-
theorem run'_toStateM {α : Type u} (comp : FreeState σ α) :
128-
(toStateM comp).run' = run' comp := by
129-
ext s₀ : 1
130-
rw [run', ← run_toStateM]
125+
-- not `simp` since `StateT.run'` is unfolded by `simp`
126+
theorem run'_toStateM {α : Type u} (comp : FreeState σ α) (s₀ : σ) :
127+
(toStateM comp).run' s₀ = pure (run' comp s₀) := by
128+
rw [run', StateT.run'_eq, run_toStateM]
131129
rfl
132130

133131
@[simp]
@@ -209,13 +207,16 @@ The canonical interpreter `toWriterT` derived from `liftM` agrees with the hand-
209207
recursive interpreter `run` for `FreeWriter`.
210208
-/
211209
@[simp]
212-
theorem run_toWriterT {α : Type u} [Monoid ω] :
213-
∀ comp : FreeWriter ω α, (toWriterT comp).run = run comp
214-
| .pure _ => by simp only [toWriterT, liftM_pure, run_pure, pure, WriterT.run]
215-
| liftBind (.tell w) cont => by
216-
simp only [toWriterT, liftM_liftBind, run_liftBind_tell] at *
217-
rw [← run_toWriterT]
218-
congr
210+
theorem run_toWriterT {α : Type u} [Monoid ω] (comp : FreeWriter ω α) :
211+
(toWriterT comp).run = pure (run comp) := by
212+
ext : 1
213+
induction comp with
214+
| pure _ => simp only [toWriterT, liftM_pure, run_pure, pure, WriterT.run]
215+
| liftBind op cont ih =>
216+
cases op
217+
simp only [toWriterT, liftM_liftBind, run_liftBind_tell, Id.run_pure] at *
218+
rw [ ← ih]
219+
simp [WriterT.run_bind, writerInterp]
219220

220221
/--
221222
`listen` captures the log produced by a subcomputation incrementally. It traverses the computation,
@@ -301,9 +302,8 @@ The canonical interpreter `toContT` derived from `liftM` agrees with the hand-wr
301302
recursive interpreter `run` for `FreeCont`.
302303
-/
303304
@[simp]
304-
theorem run_toContT {α : Type u} (comp : FreeCont r α) :
305-
(toContT comp).run = run comp := by
306-
ext k
305+
theorem run_toContT {α : Type u} (comp : FreeCont r α) (k : α → r) :
306+
(toContT comp).run k = pure (run comp k) := by
307307
induction comp with
308308
| pure a => rfl
309309
| liftBind op cont ih =>
@@ -387,7 +387,7 @@ The canonical interpreter `toReaderM` derived from `liftM` agrees with the hand-
387387
recursive interpreter `run` for `FreeReader` -/
388388
@[simp]
389389
theorem run_toReaderM {α : Type u} (comp : FreeReader σ α) (s : σ) :
390-
(toReaderM comp).run s = run comp s := by
390+
(toReaderM comp).run s = pure (run comp s) := by
391391
induction comp generalizing s with
392392
| pure a => rfl
393393
| liftBind op cont ih =>

0 commit comments

Comments
 (0)