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✝¹
Instances For
@[reducible, inline]
Lift an object of the base polynomial functor into the free monad.
Equations
- PFunctor.FreeM.lift x = PFunctor.FreeM.roll x.fst fun (y : P.B x.fst) => PFunctor.FreeM.pure (x.snd y)
Instances For
@[reducible, inline]
Lift a position of the base polynomial functor into the free monad.
Equations
Instances For
Equations
- PFunctor.FreeM.instMonadLiftObj = { monadLift := fun {α : Type ?u.10} (x : ↑P α) => PFunctor.FreeM.lift x }
@[simp]
@[simp]
@[inline]
Bind operator on FreeM P operation used in the monad definition.
Equations
- (PFunctor.FreeM.pure x_2).bind x✝ = x✝ x_2
- (PFunctor.FreeM.roll x_2 r).bind x✝ = PFunctor.FreeM.roll x_2 fun (u : P.B x_2) => (r u).bind x✝
Instances For
@[simp]
theorem
PFunctor.FreeM.bind_pure
{P : PFunctor.{uA, uB}}
{α β : Type v}
(x : α)
(r : α → P.FreeM β)
:
Equations
- One or more equations did not get rendered due to their size.
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
def
PFunctor.FreeM.construct
{P : PFunctor.{uA, uB}}
{α : Type v}
{C : P.FreeM α → Type u_1}
(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
Shoulde be possible to unify with the above
Equations
- PFunctor.FreeM.construct pure roll (PFunctor.FreeM.pure x_1) = pure x_1
- PFunctor.FreeM.construct pure roll (PFunctor.FreeM.roll x_1 r) = roll x_1 r fun (u : P.B x_1) => PFunctor.FreeM.construct pure roll (r u)
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)
def
PFunctor.FreeM.mapM
{P : PFunctor.{uA, uB}}
{m : Type uB → Type v}
{α : Type uB}
[Pure m]
[Bind m]
(s : (a : P.A) → m (P.B a))
:
P.FreeM α → m α
Canonical mapping of FreeM P into any other monad, given a map s : (a : P.A) → m (P.B a).
Equations
- PFunctor.FreeM.mapM s (PFunctor.FreeM.pure a) = pure a
- PFunctor.FreeM.mapM s (PFunctor.FreeM.roll a r) = do let u ← s a PFunctor.FreeM.mapM s (r u)
Instances For
@[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
- PFunctor.FreeM.mapMHom s = { toFun := fun (x : Type ?u.32) => PFunctor.FreeM.mapM s, toFun_pure' := ⋯, toFun_bind' := ⋯ }
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
- One or more equations did not get rendered due to their size.
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⟩