Monads¶
Monad definitions with units, multiplications, and monad laws.
monads
¶
Concrete monad instances on V-enriched FinSet.
The Monad typeclass itself lives in
quivers.monadic.typeclasses; this module provides two concrete
monad instances together with the KleisliCategory adapter.
FuzzyPowersetMonad— the powerset monad over an algebra, whose Kleisli category is the V-enriched relation category.FreeMonoidMonad— the free monoid monad on a finite alphabet, truncated to a maximum length.KleisliCategory— wraps anyMonadinstance for composition.
Both concrete monads subclass Monad and implement the
required fmap_obj / fmap / pure / join operations.
apply is inherited from Applicative and raises when the
internal-hom construction is not supplied per-instance.
FuzzyPowersetMonad
¶
FuzzyPowersetMonad(algebra: Algebra | None = None)
Bases: Monad
The fuzzy powerset monad with a given algebra.
At the set level, T(A) = A because fuzzy subsets are
represented as membership-function tensors, not as elements of a
powerset. The unit η_A = identity(A) and the multiplication
μ_A = identity(A).
Kleisli composition is V-enriched composition (>> on morphisms).
| PARAMETER | DESCRIPTION |
|---|---|
algebra
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
Source code in src/quivers/monadic/monads.py
FreeMonoidMonad
¶
FreeMonoidMonad(max_length: int = 4, algebra: Algebra | None = None)
Bases: Monad
The free monoid monad, truncated to max_length.
T(A) = FreeMonoid(generators=A, max_length=max_length) =
1 + A + A² + ... + A^max_length.
η_A : A → A*embeds each element as a length-1 word.μ_A : (A*)* → A*flattens nested words by concatenation (truncated tomax_length).
| PARAMETER | DESCRIPTION |
|---|---|
max_length
|
Maximum word length (inclusive). Defaults to 4.
TYPE:
|
algebra
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
Source code in src/quivers/monadic/monads.py
pure
¶
η_A : A → A* — embed elements as length-1 words.
Returns a morphism whose tensor is [0, I, 0, ..., 0] along
the codomain's component-axis: zero on the empty word, identity
on the length-1 component, zero elsewhere.
Source code in src/quivers/monadic/monads.py
join
¶
μ_A : (A*)* → A* — flatten nested words by concatenation.
The flattened-result indexing follows the canonical word-encoding
of FreeMonoid; flattenings whose total length exceeds
max_length are dropped.
Source code in src/quivers/monadic/monads.py
unit
¶
KleisliCategory
¶
KleisliCategory(monad: Monad)
The Kleisli category of a monad.
Objects are the same as the base category. Morphisms A → B in
the Kleisli category are morphisms A → T(B) in the base
category. Composition uses the underlying monad's
Monad.join, falling through to a closed-form
kleisli_compose method on the monad when available.
| PARAMETER | DESCRIPTION |
|---|---|
monad
|
The underlying monad instance.
TYPE:
|
Source code in src/quivers/monadic/monads.py
identity
¶
compose
¶
Kleisli composition.
For f : A → T(B) and g : B → T(C), returns
A → T(C) via the monad's bind / join construction.