Documentation

Init.Control.Lawful

@[simp]
theorem monadLift_self {m : Type u_1Type u_2} {α : Type u_1} [inst : Monad m] (x : m α) :
class LawfulFunctor (f : Type uType v) [inst : Functor f] :
Prop
  • map_const : ∀ {α β : Type u}, Functor.mapConst = Functor.map Function.const β
  • id_map : ∀ {α : Type u} (x : f α), id <$> x = x
  • comp_map : ∀ {α β γ : Type u} (g : αβ) (h : βγ) (x : f α), (h g) <$> x = h <$> g <$> x
Instances
@[simp]
theorem id_map' {m : Type u_1Type u_2} {α : Type u_1} [inst : Functor m] [inst : LawfulFunctor m] (x : m α) :
(fun a => a) <$> x = x
class LawfulApplicative (f : Type uType v) [inst : Applicative f] extends LawfulFunctor :
Prop
Instances
@[simp]
theorem pure_id_seq {f : Type u_1Type u_2} {α : Type u_1} [inst : Applicative f] [inst : LawfulApplicative f] (x : f α) :
(Seq.seq (pure id) fun x => x) = x
class LawfulMonad (m : Type uType v) [inst : Monad m] extends LawfulApplicative :
Prop
  • bind_pure_comp : ∀ {α β : Type u} (f : αβ) (x : m α), (do let a ← x pure (f a)) = f <$> x
  • bind_map : ∀ {α β : Type u} (f : m (αβ)) (x : m α), (do let a ← f a <$> x) = Seq.seq f fun x_1 => x
  • pure_bind : ∀ {α β : Type u} (x : α) (f : αm β), pure x >>= f = f x
  • bind_assoc : ∀ {α β γ : Type u} (x : m α) (f : αm β) (g : βm γ), x >>= f >>= g = x >>= fun x => f x >>= g
Instances
@[simp]
theorem bind_pure {m : Type u_1Type u_2} {α : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : m α) :
x >>= pure = x
theorem map_eq_pure_bind {m : Type u_1Type u_2} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (f : αβ) (x : m α) :
f <$> x = do let a ← x pure (f a)
theorem seq_eq_bind_map {m : Type uType u_1} {α : Type u} {β : Type u} [inst : Monad m] [inst : LawfulMonad m] (f : m (αβ)) (x : m α) :
(Seq.seq f fun x => x) = do let a ← f a <$> x
theorem bind_congr {m : Type u_1Type u_2} {α : Type u_1} {β : Type u_1} [inst : Bind m] {x : m α} {f : αm β} {g : αm β} (h : ∀ (a : α), f a = g a) :
x >>= f = x >>= g
@[simp]
theorem bind_pure_unit {m : Type u_1Type u_2} [inst : Monad m] [inst : LawfulMonad m] {x : m PUnit} :
(do x pure PUnit.unit) = x
theorem map_congr {m : Type u_1Type u_2} {α : Type u_1} {β : Type u_1} [inst : Functor m] {x : m α} {f : αβ} {g : αβ} (h : ∀ (a : α), f a = g a) :
f <$> x = g <$> x
theorem seq_eq_bind {m : Type uType u_1} {α : Type u} {β : Type u} [inst : Monad m] [inst : LawfulMonad m] (mf : m (αβ)) (x : m α) :
(Seq.seq mf fun x => x) = do let f ← mf f <$> x
theorem seqRight_eq_bind {m : Type u_1Type u_2} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : m α) (y : m β) :
(SeqRight.seqRight x fun x => y) = do let _ ← x y
theorem seqLeft_eq_bind {m : Type u_1Type u_2} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : m α) (y : m β) :
(SeqLeft.seqLeft x fun x => y) = do let a ← x let _ ← y pure a
@[simp]
theorem Id.map_eq {α : Type u_1} {β : Type u_1} (x : Id α) (f : αβ) :
f <$> x = f x
@[simp]
theorem Id.bind_eq {α : Type u_1} {β : Type u_1} (x : Id α) (f : αid β) :
x >>= f = f x
@[simp]
theorem Id.pure_eq {α : Type u_1} (a : α) :
pure a = a
theorem ExceptT.ext {m : Type u_1Type u_2} {ε : Type u_1} {α : Type u_1} [inst : Monad m] {x : ExceptT ε m α} {y : ExceptT ε m α} (h : ExceptT.run x = ExceptT.run y) :
x = y
@[simp]
theorem ExceptT.run_pure {m : Type u_1Type u_2} {α : Type u_1} {ε : Type u_1} [inst : Monad m] (x : α) :
@[simp]
theorem ExceptT.run_lift {m : Type uType v} {α : Type u} {ε : Type u} [inst : Monad m] (x : m α) :
ExceptT.run (ExceptT.lift x) = Except.ok <$> x
@[simp]
theorem ExceptT.run_throw {m : Type u_1Type u_2} {ε : Type u_1} {β : Type u_1} {e : ε} [inst : Monad m] :
@[simp]
theorem ExceptT.run_bind_lift {m : Type u_1Type u_2} {α : Type u_1} {ε : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : m α) (f : αExceptT ε m β) :
ExceptT.run (ExceptT.lift x >>= f) = do let a ← x ExceptT.run (f a)
@[simp]
theorem ExceptT.bind_throw {m : Type u_1Type u_2} {α : Type u_1} {ε : Type u_1} {β : Type u_1} {e : ε} [inst : Monad m] [inst : LawfulMonad m] (f : αExceptT ε m β) :
theorem ExceptT.run_bind {m : Type u_1Type u_2} {ε : Type u_1} {α : Type u_1} {β : Type u_1} {f : αExceptT ε m β} [inst : Monad m] (x : ExceptT ε m α) :
ExceptT.run (x >>= f) = do let _fun_discr ← ExceptT.run x match _fun_discr with | Except.ok x => ExceptT.run (f x) | Except.error e => pure (Except.error e)
@[simp]
theorem ExceptT.lift_pure {m : Type u_1Type u_2} {α : Type u_1} {ε : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (a : α) :
@[simp]
theorem ExceptT.run_map {m : Type u_1Type u_2} {α : Type u_1} {β : Type u_1} {ε : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (f : αβ) (x : ExceptT ε m α) :
theorem ExceptT.seq_eq {m : Type uType u_1} {α : Type u} {β : Type u} {ε : Type u} [inst : Monad m] (mf : ExceptT ε m (αβ)) (x : ExceptT ε m α) :
(Seq.seq mf fun x => x) = do let f ← mf f <$> x
theorem ExceptT.bind_pure_comp {m : Type u_1Type u_2} {α : Type u_1} {β : Type u_1} {ε : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (f : αβ) (x : ExceptT ε m α) :
x >>= pure f = f <$> x
theorem ExceptT.seqLeft_eq {α : Type u} {β : Type u} {ε : Type u} {m : Type uType v} [inst : Monad m] [inst : LawfulMonad m] (x : ExceptT ε m α) (y : ExceptT ε m β) :
(SeqLeft.seqLeft x fun x => y) = Seq.seq (Function.const β <$> x) fun x => y
theorem ExceptT.seqRight_eq {m : Type u_1Type u_2} {ε : Type u_1} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : ExceptT ε m α) (y : ExceptT ε m β) :
(SeqRight.seqRight x fun x => y) = Seq.seq (Function.const α id <$> x) fun x => y
theorem ReaderT.ext {m : Type u_1Type u_2} {ρ : Type u_1} {α : Type u_1} [inst : Monad m] {x : ReaderT ρ m α} {y : ReaderT ρ m α} (h : ∀ (ctx : ρ), ReaderT.run x ctx = ReaderT.run y ctx) :
x = y
@[simp]
theorem ReaderT.run_pure {m : Type u_1Type u_2} {α : Type u_1} {ρ : Type u_1} [inst : Monad m] (a : α) (ctx : ρ) :
@[simp]
theorem ReaderT.run_bind {m : Type u_1Type u_2} {ρ : Type u_1} {α : Type u_1} {β : Type u_1} [inst : Monad m] (x : ReaderT ρ m α) (f : αReaderT ρ m β) (ctx : ρ) :
ReaderT.run (x >>= f) ctx = do let a ← ReaderT.run x ctx ReaderT.run (f a) ctx
@[simp]
theorem ReaderT.run_map {m : Type u_1Type u_2} {α : Type u_1} {β : Type u_1} {ρ : Type u_1} [inst : Monad m] (f : αβ) (x : ReaderT ρ m α) (ctx : ρ) :
ReaderT.run (f <$> x) ctx = f <$> ReaderT.run x ctx
@[simp]
theorem ReaderT.run_monadLift {n : Type u_1Type u_2} {m : Type u_1Type u_3} {α : Type u_1} {ρ : Type u_1} [inst : MonadLiftT n m] (x : n α) (ctx : ρ) :
@[simp]
theorem ReaderT.run_monadMap {m : Type uType u_1} {n : Type uType u_2} {ρ : Type u} {α : Type u} [inst : Monad m] [inst : MonadFunctor n m] (f : {β : Type u} → n βn β) (x : ReaderT ρ m α) (ctx : ρ) :
@[simp]
theorem ReaderT.run_read {m : Type u_1Type u_2} {ρ : Type u_1} [inst : Monad m] (ctx : ρ) :
ReaderT.run ReaderT.read ctx = pure ctx
@[simp]
theorem ReaderT.run_seq {m : Type uType u_1} {ρ : Type u} {α : Type u} {β : Type u} [inst : Monad m] [inst : LawfulMonad m] (f : ReaderT ρ m (αβ)) (x : ReaderT ρ m α) (ctx : ρ) :
ReaderT.run (Seq.seq f fun x => x) ctx = Seq.seq (ReaderT.run f ctx) fun x => ReaderT.run x ctx
@[simp]
theorem ReaderT.run_seqRight {m : Type u_1Type u_2} {ρ : Type u_1} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : ReaderT ρ m α) (y : ReaderT ρ m β) (ctx : ρ) :
ReaderT.run (SeqRight.seqRight x fun x => y) ctx = SeqRight.seqRight (ReaderT.run x ctx) fun x => ReaderT.run y ctx
@[simp]
theorem ReaderT.run_seqLeft {m : Type u_1Type u_2} {ρ : Type u_1} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : ReaderT ρ m α) (y : ReaderT ρ m β) (ctx : ρ) :
ReaderT.run (SeqLeft.seqLeft x fun x => y) ctx = SeqLeft.seqLeft (ReaderT.run x ctx) fun x => ReaderT.run y ctx
theorem StateT.ext {σ : Type u_1} {m : Type u_1Type u_2} {α : Type u_1} {x : StateT σ m α} {y : StateT σ m α} (h : ∀ (s : σ), StateT.run x s = StateT.run y s) :
x = y
@[simp]
theorem StateT.run'_eq {m : Type u_1Type u_2} {σ : Type u_1} {α : Type u_1} [inst : Monad m] (x : StateT σ m α) (s : σ) :
StateT.run' x s = (fun a => a.fst) <$> StateT.run x s
@[simp]
theorem StateT.run_pure {m : Type u_1Type u_2} {α : Type u_1} {σ : Type u_1} [inst : Monad m] (a : α) (s : σ) :
StateT.run (pure a) s = pure (a, s)
@[simp]
theorem StateT.run_bind {m : Type u_1Type u_2} {σ : Type u_1} {α : Type u_1} {β : Type u_1} [inst : Monad m] (x : StateT σ m α) (f : αStateT σ m β) (s : σ) :
StateT.run (x >>= f) s = do let p ← StateT.run x s StateT.run (f p.fst) p.snd
@[simp]
theorem StateT.run_map {m : Type uType u_1} {α : Type u} {β : Type u} {σ : Type u} [inst : Monad m] [inst : LawfulMonad m] (f : αβ) (x : StateT σ m α) (s : σ) :
StateT.run (f <$> x) s = (fun p => (f p.fst, p.snd)) <$> StateT.run x s
@[simp]
theorem StateT.run_get {m : Type u_1Type u_2} {σ : Type u_1} [inst : Monad m] (s : σ) :
StateT.run get s = pure (s, s)
@[simp]
theorem StateT.run_set {m : Type u_1Type u_2} {σ : Type u_1} [inst : Monad m] (s : σ) (s' : σ) :
@[simp]
theorem StateT.run_modify {m : Type u_1Type u_2} {σ : Type u_1} [inst : Monad m] (f : σσ) (s : σ) :
@[simp]
theorem StateT.run_modifyGet {m : Type u_1Type u_2} {σ : Type u_1} {α : Type u_1} [inst : Monad m] (f : σα × σ) (s : σ) :
StateT.run (modifyGet f) s = pure ((f s).fst, (f s).snd)
@[simp]
theorem StateT.run_lift {m : Type uType u_1} {α : Type u} {σ : Type u} [inst : Monad m] (x : m α) (s : σ) :
StateT.run (StateT.lift x) s = do let a ← x pure (a, s)
@[simp]
theorem StateT.run_bind_lift {m : Type uType u_1} {β : Type u} {α : Type u} {σ : Type u} [inst : Monad m] [inst : LawfulMonad m] (x : m α) (f : αStateT σ m β) (s : σ) :
StateT.run (StateT.lift x >>= f) s = do let a ← x StateT.run (f a) s
@[simp]
theorem StateT.run_monadLift {m : Type uType u_1} {n : Type uType u_2} {α : Type u} {σ : Type u} [inst : Monad m] [inst : MonadLiftT n m] (x : n α) (s : σ) :
StateT.run (monadLift x) s = do let a ← monadLift x pure (a, s)
@[simp]
theorem StateT.run_monadMap {m : Type uType u_1} {n : Type uType u_2} {σ : Type u} {α : Type u} [inst : Monad m] [inst : MonadFunctor n m] (f : {β : Type u} → n βn β) (x : StateT σ m α) (s : σ) :
@[simp]
theorem StateT.run_seq {m : Type uType u_1} {α : Type u} {β : Type u} {σ : Type u} [inst : Monad m] [inst : LawfulMonad m] (f : StateT σ m (αβ)) (x : StateT σ m α) (s : σ) :
StateT.run (Seq.seq f fun x => x) s = do let fs ← StateT.run f s (fun p => (Prod.fst (αβ) σ fs p.fst, p.snd)) <$> StateT.run x fs.snd
@[simp]
theorem StateT.run_seqRight {m : Type u_1Type u_2} {σ : Type u_1} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) (s : σ) :
StateT.run (SeqRight.seqRight x fun x => y) s = do let p ← StateT.run x s StateT.run y p.snd
@[simp]
theorem StateT.run_seqLeft {m : Type uType u_1} {α : Type u} {β : Type u} {σ : Type u} [inst : Monad m] [inst : LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) (s : σ) :
StateT.run (SeqLeft.seqLeft x fun x => y) s = do let p ← StateT.run x s let p' ← StateT.run y p.snd pure (p.fst, p'.snd)
theorem StateT.seqRight_eq {m : Type u_1Type u_2} {σ : Type u_1} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) :
(SeqRight.seqRight x fun x => y) = Seq.seq (Function.const α id <$> x) fun x => y
theorem StateT.seqLeft_eq {m : Type u_1Type u_2} {σ : Type u_1} {α : Type u_1} {β : Type u_1} [inst : Monad m] [inst : LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) :
(SeqLeft.seqLeft x fun x => y) = Seq.seq (Function.const β <$> x) fun x => y