Skip to content

Commit 4f3737a

Browse files
authored
feat: monadic lemmas for FreeM.liftM (#423)
1 parent 042218c commit 4f3737a

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

Cslib/Foundations/Control/Monad/Free.lean

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,37 @@ lemma liftM_lift [LawfulMonad m] (interp : {ι : Type u} → F ι → m ι) (op
216216
@[simp]
217217
lemma liftM_bind [LawfulMonad m]
218218
(interp : {ι : Type u} → F ι → m ι) (x : FreeM F α) (f : α → FreeM F β) :
219-
(x.bind f : FreeM F β).liftM interp = (do let a ← x.liftM interp; (f a).liftM interp) := by
219+
(x.bind f).liftM interp = (do let a ← x.liftM interp; (f a).liftM interp) := by
220220
induction x generalizing f with
221221
| pure a => simp only [pure_bind, liftM_pure, LawfulMonad.pure_bind]
222222
| liftBind op cont ih =>
223223
rw [FreeM.bind, liftM_liftBind, liftM_liftBind, bind_assoc]
224224
simp_rw [ih]
225225

226+
@[simp]
227+
lemma liftM_map [LawfulMonad m]
228+
(interp : {ι : Type u} → F ι → m ι) (f : α → β) (x : FreeM F α) :
229+
(x.map f).liftM interp = f <$> x.liftM interp := by
230+
simp_rw [← bind_pure_comp, ← LawfulMonad.bind_pure_comp, liftM_bind, Function.comp, liftM_pure]
231+
232+
@[simp]
233+
lemma liftM_seq [LawfulMonad m]
234+
(interp : {ι : Type u} → F ι → m ι) (x : FreeM F (α → β)) (y : FreeM F α) :
235+
(x <*> y).liftM interp = x.liftM interp <*> y.liftM interp := by
236+
simp [seq_eq_bind_map]
237+
238+
@[simp]
239+
lemma liftM_seqLeft [LawfulMonad m]
240+
(interp : {ι : Type u} → F ι → m ι) (x : FreeM F α) (y : FreeM F β) :
241+
(x <* y).liftM interp = x.liftM interp <* y.liftM interp := by
242+
simp [seqLeft_eq_bind]
243+
244+
@[simp]
245+
lemma liftM_seqRight [LawfulMonad m]
246+
(interp : {ι : Type u} → F ι → m ι) (x : FreeM F α) (y : FreeM F β) :
247+
(x *> y).liftM interp = x.liftM interp *> y.liftM interp := by
248+
simp [seqRight_eq_bind]
249+
226250
/--
227251
A predicate stating that `interp : FreeM F α → m α` is an interpreter for the effect
228252
handler `handler : ∀ {α}, F α → m α`.

0 commit comments

Comments
 (0)