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
49 50 | |
unit
¶
η_A : A → T(A); alias for pure.
Source code in src/quivers/monadic/monads.py
76 77 78 | |
multiply
¶
μ_A : T(T(A)) → T(A); alias for join.
Source code in src/quivers/monadic/monads.py
80 81 82 | |
kleisli_compose
¶
Kleisli composition; V-enriched composition via >>.
Source code in src/quivers/monadic/monads.py
84 85 86 | |
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
110 111 112 113 114 | |
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
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
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
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
unit
¶
Alias for pure.
Source code in src/quivers/monadic/monads.py
201 202 203 | |
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
230 231 | |
identity
¶
Kleisli identity: η_A : A → T(A).
Source code in src/quivers/monadic/monads.py
237 238 239 | |
compose
¶
Kleisli composition.
For f : A → T(B) and g : B → T(C), returns
A → T(C) via the monad's bind / join construction.
Source code in src/quivers/monadic/monads.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |