pub struct CausalMonad;Expand description
CausalMonad is the concrete implementation of the MonadEffect3 trait for the
CausalEffectSystem. It provides the fundamental pure and bind operations
that enable monadic programming within the DeepCausality framework.
This monad is designed to manage the flow of CausalPropagatingEffects, ensuring
that errors are handled gracefully and a comprehensive log of operations is maintained.
§pure function
pure(value) lifts a raw value T into the monadic context, creating a new
CausalPropagatingEffect. This effect starts with:
- The provided
value. - No error (
None). - An empty
CausalEffectLog.
This is the entry point for any value that needs to enter the causal effect system and participate in monadic computations.
§bind function
bind(effect, f) is the sequencing operator of the monad. It takes an existing
CausalPropagatingEffect and a function f (which itself returns a new effect),
and orchestrates their execution:
-
Error Short-circuiting: It first checks if the
incoming_effectalready contains an error. If so,fis not executed, and a newCausalPropagatingEffectis immediately returned, carrying forward the original error and logs. Thevalueof the new effect is set toU::default()as the computation was aborted. -
Function Application: If the
incoming_effectis successful (no error), itsvalueis extracted and passed to the functionf. The functionfthen performs its computation and returns anext_effect. -
Log Aggregation: The
logsfrom theincoming_effectare combined with thelogsgenerated by thenext_effect(from functionf). This ensures that the entire history of operations is preserved in the resulting effect.
The bind operation is crucial for building complex, sequential causal reasoning
pipelines where each step’s outcome (value, error, and logs) correctly influences
the subsequent steps.
Trait Implementations§
Source§impl Intervenable<CausalEffectSystem> for CausalMonad
impl Intervenable<CausalEffectSystem> for CausalMonad
Source§fn intervene<T>(
effect: CausalPropagatingEffect<T, <CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>,
new_value: T,
) -> CausalPropagatingEffect<T, <CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>where
T: Debug,
fn intervene<T>(
effect: CausalPropagatingEffect<T, <CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>,
new_value: T,
) -> CausalPropagatingEffect<T, <CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>where
T: Debug,
Source§impl MonadEffect3<CausalEffectSystem> for CausalMonadwhere
<CausalEffectSystem as Effect3>::HktWitness: Functor<<CausalEffectSystem as Effect3>::HktWitness> + Sized,
impl MonadEffect3<CausalEffectSystem> for CausalMonadwhere
<CausalEffectSystem as Effect3>::HktWitness: Functor<<CausalEffectSystem as Effect3>::HktWitness> + Sized,
Source§fn pure<T>(
value: T,
) -> <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<T>
fn pure<T>( value: T, ) -> <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<T>
Source§fn bind<T, U, Func>(
effect: <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<T>,
f: Func,
) -> <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<U>where
Func: FnMut(T) -> <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<U>,
U: Default,
fn bind<T, U, Func>(
effect: <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<T>,
f: Func,
) -> <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<U>where
Func: FnMut(T) -> <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<U>,
U: Default,
Source§impl<I, O, D, S, T, ST, SYM, VS, VT> MonadicCausable<CausalMonad> for Causaloid<I, O, D, S, T, ST, SYM, VS, VT>
Implements the MonadicCausable trait for Causaloid.
impl<I, O, D, S, T, ST, SYM, VS, VT> MonadicCausable<CausalMonad> for Causaloid<I, O, D, S, T, ST, SYM, VS, VT>
Implements the MonadicCausable trait for Causaloid.
This implementation provides the core evaluation logic for Causaloids,
leveraging monadic principles to handle the flow of effects, errors, and logs.
The evaluation strategy varies based on the CausaloidType (Singleton, Collection, or Graph).
Source§fn evaluate(&self, incoming_effect: &PropagatingEffect) -> PropagatingEffect
fn evaluate(&self, incoming_effect: &PropagatingEffect) -> PropagatingEffect
Evaluates the causal effect of this Causaloid given an incoming_effect.
The evaluation process is monadic, ensuring that errors are propagated
and a comprehensive log of operations is maintained. The specific
evaluation strategy depends on the CausaloidType.
§Arguments
incoming_effect- ThePropagatingEffectrepresenting the input to this causaloid.
§Returns
A PropagatingEffect containing the result of the causal evaluation,
any errors encountered, and a complete log of the operations performed.
§Log Provenance
To meet the strict requirements of auditable and provable reasoning, this
implementation guarantees that the full, ordered history of operations is
preserved in the logs field of the returned PropagatingEffect. Existing
logs from the incoming_effect are always preserved and appended to.
The mechanism differs slightly by type:
-
Singleton: Uses a monadicbindchain. Each step in the chain (input conversion, execution, output conversion) automatically and safely appends its logs to the accumulated logs of the previous step. -
Collection: Sequentially evaluates each causaloid in the collection. The fullPropagatingEffect(value and all logs) from one evaluation step is used as the complete input for the next, ensuring the log history grows correctly throughout the sequential chain. -
Graph: First, it logs its own evaluation context. It then delegates to a recursive subgraph evaluation. Finally, it prepends its own context log to the complete log history returned by the subgraph, ensuring the parent-child reasoning hierarchy is captured in the final log.
In all cases, if an error occurs, the evaluation short-circuits and returns an effect containing the error and all logs accumulated up to the point of failure.