lean4-htt/tests/lean/run/do_eqv_proofs.lean
2021-02-23 12:38:00 -08:00

22 lines
612 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

theorem ex1 [Monad m] [LawfulMonad m] (b : Bool) (ma : m α) (mb : α → m α) :
(do let mut x ← ma
if b then
x ← mb x
pure x)
=
(ma >>= fun x => if b then mb x else pure x) := by
cases b <;> simp
attribute [simp] map_eq_pure_bind seq_eq_bind_map
theorem ex2 [Monad m] [LawfulMonad m] (b : Bool) (ma : m α) (mb : α → m α) (a : α) :
(do let mut x ← ma
if b then
x ← mb x
pure x)
=
(StateT.run' (m := m)
(do ma >>= set
if b then get >>= fun x => mb x >>= set
get) a) := by
cases b <;> simp