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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
use crate::;
/// The `Monad` trait extends `Functor` and `Pure` by providing the `bind` operation
/// for sequencing computations that produce effectful values.
///
/// # Design Note: Pure-Based Hierarchy
///
/// Unlike the Haskell convention (`Monad: Applicative`), this trait extends `Functor + Pure`
/// directly. This enables **strict constrained witnesses** (like `StrictCausalTensorWitness`)
/// to implement `Monad` without being blocked by `Applicative`'s closure constraint.
///
/// Both `Applicative` and `Monad` share the same `pure` operation via the `Pure` trait.
///
/// # Constraint Support
///
/// The `bind` method requires types to satisfy the HKT's constraint. This ensures type-safe
/// chaining for constrained types like `CausalTensor<T>` where `T: TensorData`.
///
/// # Laws (Informal)
///
/// 1. **Left Identity**: `bind(pure(a), f) == f(a)`
/// 2. **Right Identity**: `bind(m, pure) == m`
/// 3. **Associativity**: `bind(bind(m, f), g) == bind(m, |x| bind(f(x), g))`
///
/// # Type Parameters
///
/// * `F`: A Higher-Kinded Type (HKT) witness that represents the type constructor
/// (e.g., `OptionWitness`, `ResultWitness<E>`, `VecWitness`).