Free Monad of a Polynomial Functor #
We define the free monad on a polynomial functor (PFunctor), and prove some basic properties.
The free monad on a polynomial functor.
This extends the W-type construction with an extra pure constructor.
- pure {P : PFunctor.{uA, uB}} {α : Type v} (x : α) : P.FreeM α
- roll {P : PFunctor.{uA, uB}} {α : Type v} (a : P.A) (r : P.B a → P.FreeM α) : P.FreeM α
Instances For
Equations
def
PFunctor.instInhabitedFreeM.default
{a✝ : PFunctor.{u_1, u_2}}
{a✝¹ : Type u_3}
[Inhabited a✝¹]
:
a✝.FreeM a✝¹
Equations
Instances For
@[reducible, inline]
Lift an object of the base polynomial functor into the free monad.
Equations
Instances For
@[reducible, inline]
Lift a position of the base polynomial functor into the free monad.
Equations
Instances For
Equations
@[simp]
@[simp]
@[inline]
Bind operator on FreeM P operation used in the monad definition.
Equations
Instances For
@[simp]
theorem
PFunctor.FreeM.bind_pure
{P : PFunctor.{uA, uB}}
{α β : Type v}
(x : α)
(r : α → P.FreeM β)
:
theorem
PFunctor.FreeM.monad_bind_def
{P : PFunctor.{uA, uB}}
{α β : Type v}
(x : P.FreeM α)
(g : α → P.FreeM β)
:
def
PFunctor.FreeM.inductionOn
{P : PFunctor.{uA, uB}}
{α : Type v}
{C : P.FreeM α → Prop}
(pure : ∀ (x : α), C (pure x))
(roll : ∀ (x : P.A) (r : P.B x → P.FreeM α), (∀ (y : P.B x), C (r y)) → C (roll x r))
(oa : P.FreeM α)
:
C oa
Proving a predicate C of FreeM P α requires two cases:
pure xfor somex : αroll x r hfor somex : P.A,r : P.B x → FreeM P α, andh : ∀ y, C (r y)Note that we can't useSort vinstead ofPropdue to universe levels.
Equations
Instances For
@[simp]
theorem
PFunctor.FreeM.construct_roll
{P : PFunctor.{uA, uB}}
{α : Type v}
{C : P.FreeM α → Type u_1}
(h_pure : (x : α) → C (pure x))
(h_roll : (x : P.A) → (r : P.B x → P.FreeM α) → ((y : P.B x) → C (r y)) → C (roll x r))
(x : P.A)
(r : P.B x → P.FreeM α)
:
FreeM.construct h_pure h_roll (roll x r) = h_roll x r fun (u : P.B x) => FreeM.construct h_pure h_roll (r u)
@[simp]
theorem
PFunctor.FreeM.mapM_pure'
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
{α : Type uB}
[Monad m]
(s : (a : P.A) → m (P.B a))
(x : α)
:
@[simp]
theorem
PFunctor.FreeM.mapM_pure
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
{α : Type uB}
[Monad m]
(s : (a : P.A) → m (P.B a))
(x : α)
:
@[simp]
theorem
PFunctor.FreeM.mapM_bind
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
[Monad m]
(s : (a : P.A) → m (P.B a))
[LawfulMonad m]
{α β : Type uB}
(x : P.FreeM α)
(y : α → P.FreeM β)
:
@[simp]
theorem
PFunctor.FreeM.mapM_bind'
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
[Monad m]
(s : (a : P.A) → m (P.B a))
[LawfulMonad m]
{α β : Type uB}
(x : P.FreeM α)
(y : α → P.FreeM β)
:
@[simp]
theorem
PFunctor.FreeM.mapM_map
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
[Monad m]
(s : (a : P.A) → m (P.B a))
[LawfulMonad m]
{α β : Type uB}
(x : P.FreeM α)
(f : α → β)
:
@[simp]
theorem
PFunctor.FreeM.mapM_seq
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
[Monad m]
[LawfulMonad m]
{α β : Type uB}
(s : (a : P.A) → m (P.B a))
(x : P.FreeM (α → β))
(y : P.FreeM α)
:
@[simp]
theorem
PFunctor.FreeM.mapM_lift
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
{α : Type uB}
[Monad m]
[LawfulMonad m]
(s : (a : P.A) → m (P.B a))
(x : ↑P α)
:
@[simp]
theorem
PFunctor.FreeM.mapM_liftA
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
[Monad m]
[LawfulMonad m]
(s : (a : P.A) → m (P.B a))
(x : P.A)
:
def
PFunctor.FreeM.mapMHom
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
[Monad m]
[LawfulMonad m]
(s : (a : P.A) → m (P.B a))
:
FreeM.mapM as a monad homomorphism.
Equations
Instances For
@[simp]
theorem
PFunctor.FreeM.mapMHom_toFun_eq
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
{α : Type uB}
[Monad m]
[LawfulMonad m]
(s : (a : P.A) → m (P.B a))
:
def
PFunctor.FreeM.mapMHom'
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
[Monad m]
[LawfulMonad m]
(s : NatHom (↑P) m)
:
Equations
Instances For
@[simp]
theorem
PFunctor.FreeM.mapMHom'_toFun_eq
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
{α : Type uB}
[Monad m]
[LawfulMonad m]
(s : NatHom (↑P) m)
:
(FreeM.mapMHom' s).toFun α = FreeM.mapM fun (t : P.A) => (fun {α : Type uB} (x : ↑P α) => s.toFun α x) ⟨t, id⟩