pub trait ParametricMonad<M: HKT3Unbound> {
// Required methods
fn pure<S, A>(value: A) -> M::Type<S, S, A>;
fn ibind<S1, S2, S3, A, B, F>(
m: M::Type<S1, S2, A>,
f: F,
) -> M::Type<S1, S3, B>
where F: FnMut(A) -> M::Type<S2, S3, B>;
}Expand description
The ParametricMonad (or Indexed Monad) trait allows for monadic computations where the
type of the underlying state can change at each step.
§Category Theory
An Indexed Monad is a generalization of a Monad. Instead of a single endofunctor $M: \mathcal{C} \to \mathcal{C}$, we have a family of functors $M_{ij}: \mathcal{C} \to \mathcal{C}$ indexed by states $i, j$.
- Bind: $M_{ij}(A) \to (A \to M_{jk}(B)) \to M_{ik}(B)$
§Mathematical Definition
It models a category where objects are states and morphisms are state transitions carrying a value.
The ibind operation composes these transitions: $(i \to j) \circ (j \to k) = (i \to k)$.
§Use Cases
- Phase Transitions: Simulating a system evolving from
Fluid->Gas->Plasma. - Protocol State Machines: Enforcing correct ordering of operations (e.g.,
Unauthenticated->Authenticated). - Topology Rewrites: Changing the mesh type from
TriangulartoHexagonalduring a simulation step.
Required Methods§
Sourcefn pure<S, A>(value: A) -> M::Type<S, S, A>
fn pure<S, A>(value: A) -> M::Type<S, S, A>
Injects a value into a computation that doesn’t change the state type ($S \to S$).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.