Free Monads #
This file defines the free monad on an arbitrary mapping f : Type u → Type v
.
This has the undesirable property of raising the universe level by 1, which means we can't pass
a FreeMonad f
object as a continuation into an interactive protocol.
See PFunctor.FreeM
for the free monad of a polynomial functor, which does not raise the universe level.
The free monad on a functor f
is the type freely generated by values of type f α
and the operations pure
and bind
. Implemented directly rather than as a quotient.
Slightly different than constructions of free monads in Haskell because of universe issues.
- pure {f : Type u → Type v} {α : Type w} (x : α) : FreeMonad f α
- roll {f : Type u → Type v} {α : Type w} {β : Type u} (x : f β) (r : β → FreeMonad f α) : FreeMonad f α
Instances For
@[simp]
@[simp]
Equations
def
FreeMonad.inductionOn
{f : Type u → Type v}
{α : Type u}
{C : FreeMonad f α → Prop}
(pure : ∀ (x : α), C (pure x))
(roll : ∀ {β : Type u} (x : f β) (r : β → FreeMonad f α), (∀ (y : β), C (r y)) → C (liftM x >>= r))
(oa : FreeMonad f α)
:
C oa
Proving something about FreeMonad f α
only requires two cases:
pure x
for somex : α
Note that we can't useSort v
instead ofProp
due to universe levels.
Equations
Instances For
def
FreeMonad.construct
{f : Type u → Type v}
{α : Type u}
{C : FreeMonad f α → Type u_1}
(pure : (x : α) → C (pure x))
(roll : {β : Type u} → (x : f β) → (r : β → FreeMonad f α) → ((y : β) → C (r y)) → C (liftM x >>= r))
(oa : FreeMonad f α)
:
C oa
Shoulde be possible to unify with the above
Equations
Instances For
@[simp]
theorem
FreeMonad.construct_roll
{f : Type u → Type v}
{α β : Type u}
{C : FreeMonad f α → Type u_1}
(h_pure : (x : α) → C (pure x))
(h_roll : {β : Type u} → (x : f β) → (r : β → FreeMonad f α) → ((y : β) → C (r y)) → C (liftM x >>= r))
(x : f β)
(r : β → FreeMonad f α)
:
FreeMonad.construct h_pure (fun {β : Type u} => h_roll) (roll x r) = h_roll x r fun (u : β) => FreeMonad.construct h_pure (fun {β : Type u} => h_roll) (r u)
@[simp]
@[simp]