1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
use crate::;
/// 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 `Triangular` to `Hexagonal` during a simulation step.