Morphisms Between Monads #
A morphism of monads is a family m α → n α, natural in α, preserving pure
and bind. There are two useful presentations, and this file is deliberate
about which one it owns.
Unbundled: Lean core #
When the morphism is canonical for the pair (m, n) and should be found by
instance search, it belongs to core's lifting hierarchy: MonadLift /
MonadLiftT supply the map and LawfulMonadLift / LawfulMonadLiftT
(Init/Control/Lawful/MonadLift/) supply exactly the two laws above. Core
carries instances for the standard transformer stack and a liftM_* simp set,
so nothing of that shape should be re-derived here.
Bundled: this file #
When the morphism is data — chosen at the call site, passed around, composed,
or mapped over — instance search is the wrong mechanism and a first-class arrow
is needed. Core has no bundled form, so MonadHom (notation m →ᵐ n) is that
arrow, with MonadHom.comp (∘ₘ), MonadHom.id, and StateT.mapHom for
transporting one along a transformer. NatHom is the underlying natural
transformation without the laws; PFunctor.FreeM.liftMHom' consumes it
directly.
MonadHom.ofLift is the bridge: any lawful lift induces a bundled morphism.
There is deliberately no converse instance — turning an arbitrary MonadHom
into a MonadLift would make instance search pick between morphisms that are
genuinely different maps.
Why there is no PureHom / BindHom hierarchy #
Mathlib splits OneHom from MulHom (and ZeroHom from AddHom) because those
component morphisms are useful independently, and because many richer morphism
types share their laws through the corresponding HomClass hierarchy. The
old sketches in this file proposed the analogous PureHom, BindHom, and
MonadHomClass, but PolyFun, VCVio, and ArkLib have no consumer of either
partial morphism. A PureHom would only preserve a pointing; a BindHom
would only become meaningful after choosing laws for a non-unital semimonad.
Neither abstraction exists in this stack.
The neighbouring upstream APIs make the same atomic choice. Lean v4.34's
LawfulMonadLift(T) packages the pure and bind laws together, and mathlib's
categorical MonadHom packages compatibility with both the unit and
multiplication. Batteries adds orthogonal preservation laws, such as
LawfulAlternativeLift, alongside a monad lift rather than splitting its two
monad laws.
A family-aware analogue of FunLike may become worthwhile once multiple
bundled morphism types need common lemmas. The previous
(α : Type u) → FunLike F (m α) (n α) sketch did not provide one coherent
function-like view of the whole polymorphic family, and there is only one such
arrow type today. The decision is therefore to keep MonadHom atomic and not
add speculative component structures or hom classes. A real pointed-functor,
semimonad, or second bundled-morphism consumer should reopen that decision and
arrive with the corresponding laws and generic tests.
The unused MonadEquiv module is omitted for the same reason. If a consumer
needs monad equivalences, the minimal design is two inverse MonadHoms, not a
parallel hierarchy of unused PureEquiv and BindEquiv structures.
Mathlib's CategoryTheory.MonadHom is a third presentation, at restricted
universes and in the categorical idiom; the Type-level form here is what the
free-monad and interaction layers actually consume.
A MonadHom m n bundles a monad map m ⟶ n (represented as a NatHom) with proofs that
it respects the bind and pure operations in the underlying monad.
Instances For
Extensionality for monad homomorphisms: two morphisms agreeing on every argument at every type are equal.
Construct a MonadHom from a lawful monad lift.
Instances For
Infix notation for composition of monad homomorphisms, G ∘ₘ F.
Instances For
StateT σ is functorial on monad morphisms: a monad morphism φ : m →ᵐ n lifts to a monad
morphism StateT σ m →ᵐ StateT σ n, acting on the underlying state-run and threading the state
unchanged. This transports the naturality of a fold (for example,
FreeM.liftM_natural) through a stateful
handler — the form a StateT-threaded semantic morphism (such as an evaluation-distribution map)
needs.