@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44Authors: Kim Morrison
55-/
66import Batteries.Classes.SatisfiesM
7+ import Batteries.Control.Monad
78import Batteries.Data.Array.Monadic
89
910namespace Vector
@@ -29,36 +30,6 @@ theorem toArray_mapIdxM [Monad m] [LawfulMonad m] (a : Vector α n) (f : Nat →
2930 toArray <$> a.mapIdxM f = a.toArray.mapIdxM f := by
3031 exact toArray_mapFinIdxM _ _
3132
32- theorem _root_.LawfulFunctor.map_inj_right_of_nonempty [Functor f] [LawfulFunctor f] [Nonempty α]
33- {g : α → β} (h : ∀ {x y : α}, g x = g y → x = y) {x y : f α} :
34- g <$> x = g <$> y ↔ x = y := by
35- constructor
36- · open Classical in
37- let g' a := if h : ∃ b, g b = a then h.choose else Classical.ofNonempty
38- have g'g a : g' (g a) = a := by
39- simp only [exists_apply_eq_apply, ↓reduceDIte, g']
40- exact h (_ : ∃ b, g b = g a).choose_spec
41- intro h'
42- simpa only [Functor.map_map, g'g, id_map'] using congrArg (g' <$> ·) h'
43- · intro h'
44- rw [h']
45-
46- theorem _root_.LawfulMonad.map_inj_right [Monad m] [LawfulMonad m]
47- {f : α → β} (h : ∀ {x y : α}, f x = f y → x = y) {x y : m α} :
48- f <$> x = f <$> y ↔ x = y := by
49- by_cases hempty : Nonempty α
50- · exact LawfulFunctor.map_inj_right_of_nonempty h
51- · constructor
52- · intro h'
53- have (z : m α) : z = (do let a ← z; let b ← pure (f a); x) := by
54- conv => lhs; rw [← bind_pure z]
55- congr; funext a
56- exact (hempty ⟨a⟩).elim
57- rw [this x, this y]
58- rw [← bind_assoc, ← map_eq_pure_bind, h', map_eq_pure_bind, bind_assoc]
59- · intro h'
60- rw [h']
61-
6233theorem mapM_mk [Monad m] [LawfulMonad m] [MonadSatisfying m]
6334 (a : Array α) (h : a.size = n) (f : α → m β) :
6435 (Vector.mk a h).mapM f =
0 commit comments