Monad ↔ Arrow Bridges¶
The bridges translate between the monad and arrow
interfaces (Hughes, 2000). Kleisli presents functions that return monadic values as
Kleisli arrows, and ArrowMonad gives a monad
interface to an arrow that supports application: the identity monad for the function arrow and the
monad m for Kleisli(m), while any other arrow raises TypeError. The kleisli and arrow_monad helpers build them
(bridges between the hierarchies), and
each construction is lawful only when the identity and composition laws of its argument hold
(Moggi, 1991; Wadler, 1992).
bridges
¶
Bridges between the monad and arrow typeclass towers.
Three canonical conversions:
kleisli— given aMonadinstancem, produce aKleisli(m)arrow whose hom fromAtoBis the V-Rel morphism setHom(A, m(B)).arrow_monad— given anArrowApplyinstancea, produce aMonadwhose underlying functor isArrowMonad(a)(α) = a(1, α).cokleisli— comonadic dual ofkleisli.
Each bridge is realized at the value level as concrete morphism
constructions: compose is Kleisli composition (fmap-then-join),
first is the monad's strength applied to the second-factor
input, app is the canonical evaluator over the function-space
encoding [A → B]. Hughes develops the relation between monads and
arrows Hughes (2000). Recovering a monad from a suitable Kleisli arrow
uses the identification of arrows out of the unit with monadic values; this
is a correspondence under the required laws, not a claim that these runtime
objects or theory records are literally identical.
Kleisli
didactic-model
¶
Bases: ValueModel
The Kleisli arrow of a monad.
Hom from A to B is the set of morphisms A → m(B) in
V-Rel. Composition is Kleisli composition (fmap, then join);
identity is Monad.pure. first is realized via the
canonical monad strength; app evaluates a function-space
embedding through the monad's Monad.apply.
monad is held opaquely so the typeclass-ABC reference
survives in-process identity through with_ without panproto
schema validation; the field does not round-trip through JSON.
It compares by identity: two Kleisli categories are equal exactly
when they wrap the same monad object.
| ATTRIBUTE | DESCRIPTION |
|---|---|
monad |
The underlying monad instance.
TYPE:
|
compose
¶
Kleisli composition f ; g = join ∘ fmap(g) ∘ f.
f : A → m(B), g : B → m(C) ⊢ g ∘_K f : A → m(C).
Source code in src/quivers/monadic/bridges.py
first
¶
first(f) : (A × C) → m(B × C) via the monad's strength.
Realized as (f × id_C) ; strength_m(B, C).
Source code in src/quivers/monadic/bridges.py
app
¶
app : m([A → B]) × m(A) → m(B) via the monad's apply.
Routes through the Applicative-level apply, which every Monad has by inclusion.
Source code in src/quivers/monadic/bridges.py
ArrowMonad
didactic-model
¶
Bases: ValueModel
The monad induced by an ArrowApply arrow.
For a lawful ArrowApply interface a, the corresponding monadic
values have the form ArrowMonad(a)(α) = a(1, α), where 1 is the
monoidal unit Hughes (2000).
Realized concretely:
fmap_obj(A) = A(the underlying carrier coincides with the target type of the arrow's hom from the unit);pure(A)is the arrow'sarr(id_A);join(A)is the arrow'sappmorphism on the unit-anchored arrow values.
arrow is held opaquely and compares by identity: two arrow
monads are equal exactly when they wrap the same arrow object.
| ATTRIBUTE | DESCRIPTION |
|---|---|
arrow |
The underlying arrow.
TYPE:
|
CoKleisli
didactic-model
¶
Bases: ValueModel
The CoKleisli category of a comonad.
Hom from A to B is the set of morphisms W(A) → B.
Composition is the comonadic CoKleisli composition
f =>> g = g ∘ W(f) ∘ δ_A; identity is the counit ε_A.
CoKleisli is registered as Category_ rather than
Arrow because the arrow first derivation requires
a comonadic costrength W(A × C) → W(A) × C, which is not
canonical for an arbitrary comonad. When the underlying comonad
supplies a costrength(A, C) method, that morphism composes
with parallel(f, ε_C ∘ W(π_2)) to realise first as the
full Arrow primitive; the helper first_via_costrength
constructs that morphism given an explicit costrength.
comonad is held opaquely so the typeclass-ABC reference
survives in-process identity without panproto schema validation.
It compares by identity: two CoKleisli categories are equal
exactly when they wrap the same comonad object.
| ATTRIBUTE | DESCRIPTION |
|---|---|
comonad |
The underlying comonad instance.
TYPE:
|
first_via_costrength
¶
Realise first(f) given an explicit comonad costrength.
costrength : W(A × C) → W(A) × C is the comonad-specific
morphism (analogous to the monad strength). With it,
first(f, C) = costrength ; (f × id_C) is a valid CoKleisli
arrow W(A × C) ⇝ B × C.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
A CoKleisli arrow
TYPE:
|
C
|
The fixed second-factor object.
TYPE:
|
costrength
|
The comonad's costrength
TYPE:
|
Source code in src/quivers/monadic/bridges.py
kleisli
¶
arrow_monad
¶
arrow_monad(arrow: ArrowApply) -> ArrowMonad
Wrap an ArrowApply arrow as a Monad.
| PARAMETER | DESCRIPTION |
|---|---|
arrow
|
The arrow whose
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ArrowMonad
|
The monad of |
Source code in src/quivers/monadic/bridges.py
cokleisli
¶
Wrap a Comonad as a CoKleisli category.
The result is registered as Category_ (always) but not
Arrow; promoting to an Arrow requires the user-supplied
costrength routed through CoKleisli.first_via_costrength.
| PARAMETER | DESCRIPTION |
|---|---|
comonad
|
The comonad whose CoKleisli category is built.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CoKleisli
|
The CoKleisli category of |
Source code in src/quivers/monadic/bridges.py
Cited sources¶
John Hughes. Generalising Monads to Arrows. Science of Computer Programming, 37(1–3):67–111, 2000. URL: https://www.sciencedirect.com/science/article/pii/S0167642399000234, doi:10.1016/S0167-6423(99)00023-4.
Eugenio Moggi. Notions of Computation and Monads. Information and Computation, 93(1):55–92, 1991. URL: https://www.sciencedirect.com/science/article/pii/0890540191900524, doi:10.1016/0890-5401(91)90052-4.
Philip Wadler. The Essence of Functional Programming. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1–14. ACM, 1992. URL: https://doi.org/10.1145/143165.143169, doi:10.1145/143165.143169.