@@ -75,13 +75,14 @@ lemma get_def : (get : FreeState σ σ) = .lift .get := rfl
7575lemma set_def (s : σ) : (set s : FreeState σ PUnit) = .lift (.set s) := rfl
7676
7777/-- Interpret `StateF` operations into `StateM`. -/
78+ @[simp]
7879def stateInterp {α : Type u} : StateF σ α → StateM σ α
7980 | .get => MonadStateOf.get
8081 | .set s => MonadStateOf.set s
8182
8283/-- Convert a `FreeState` computation into a `StateM` computation. This is the canonical
8384interpreter derived from `liftM`. -/
84- def toStateM {α : Type u} (comp : FreeState σ α) : StateM σ α :=
85+ abbrev toStateM {α : Type u} (comp : FreeState σ α) : StateM σ α :=
8586 comp.liftM stateInterp
8687
8788/-- `toStateM` is the unique interpreter extending `stateInterp`. -/
@@ -176,12 +177,13 @@ open WriterF
176177variable {ω : Type u} {α : Type u}
177178
178179/-- Interpret `WriterF` operations into `WriterT`. -/
180+ @[simp]
179181def writerInterp {α : Type u} : WriterF ω α → WriterT ω Id α
180182 | .tell w => MonadWriter.tell w
181183
182184/-- Convert a `FreeWriter` computation into a `WriterT` computation. This is the canonical
183185interpreter derived from `liftM`. -/
184- def toWriterT {α : Type u} [Monoid ω] (comp : FreeWriter ω α) : WriterT ω Id α :=
186+ abbrev toWriterT {α : Type u} [Monoid ω] (comp : FreeWriter ω α) : WriterT ω Id α :=
185187 comp.liftM writerInterp
186188
187189/-- `toWriterT` is the unique interpreter extending `writerInterp`. -/
@@ -235,12 +237,12 @@ theorem run_toWriterT {α : Type u} [Monoid ω] (comp : FreeWriter ω α) :
235237 (toWriterT comp).run = pure (run comp) := by
236238 ext : 1
237239 induction comp with
238- | pure _ => simp only [toWriterT, liftM_pure, run_pure, pure, WriterT.run]
240+ | pure _ => simp only [liftM_pure, run_pure, pure, WriterT.run]
239241 | liftBind op cont ih =>
240242 cases op
241- simp only [toWriterT, liftM_liftBind, run_liftBind_tell, Id.run_pure] at *
243+ simp only [liftM_liftBind, run_liftBind_tell, Id.run_pure] at *
242244 rw [ ← ih]
243- simp [WriterT.run_bind, writerInterp ]
245+ simp [WriterT.run_bind]
244246
245247/--
246248`listen` captures the log produced by a subcomputation incrementally. It traverses the computation,
@@ -304,12 +306,13 @@ namespace FreeCont
304306variable {r : Type u} {α : Type v} {β : Type w}
305307
306308/-- Interpret `ContF r` operations into `ContT r Id`. -/
309+ @[simp]
307310def contInterp : ContF r α → ContT r Id α
308- | .callCC g => g
311+ | .callCC g => .mk fun k => pure <| g fun a => (k a).run
309312
310313/-- Convert a `FreeCont` computation into a `ContT` computation. This is the canonical
311314interpreter derived from `liftM`. -/
312- def toContT {α : Type u} (comp : FreeCont r α) : ContT r Id α :=
315+ abbrev toContT {α : Type u} (comp : FreeCont r α) : ContT r Id α :=
313316 comp.liftM contInterp
314317
315318/-- `toContT` is the unique interpreter extending `contInterp`. -/
@@ -331,7 +334,7 @@ theorem run_toContT {α : Type u} (comp : FreeCont r α) (k : α → r) :
331334 induction comp with
332335 | pure a => rfl
333336 | liftBind op cont ih =>
334- simp only [toContT, FreeM.liftM]
337+ simp only [FreeM.liftM]
335338 cases op
336339 simp only [ContT.run_bind]
337340 congr with x
@@ -398,12 +401,13 @@ lemma read_def : (read : FreeReader σ σ) = .lift .read := rfl
398401instance : MonadReader σ (FreeReader σ) := inferInstance
399402
400403/-- Interpret `ReaderF` operations into `ReaderM`. -/
404+ @[simp]
401405def readInterp {α : Type u} : ReaderF σ α → ReaderM σ α
402406 | .read => MonadReaderOf.read
403407
404408/-- Convert a `FreeReader` computation into a `ReaderM` computation. This is the canonical
405409interpreter derived from `liftM`. -/
406- def toReaderM {α : Type u} (comp : FreeReader σ α) : ReaderM σ α :=
410+ abbrev toReaderM {α : Type u} (comp : FreeReader σ α) : ReaderM σ α :=
407411 comp.liftM readInterp
408412
409413/-- `toReaderM` is the unique interpreter extending `readInterp`. -/
0 commit comments