CausalMonad

Struct CausalMonad 

Source
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:

  1. Error Short-circuiting: It first checks if the incoming_effect already contains an error. If so, f is not executed, and a new CausalPropagatingEffect is immediately returned, carrying forward the original error and logs. The value of the new effect is set to U::default() as the computation was aborted.

  2. Function Application: If the incoming_effect is successful (no error), its value is extracted and passed to the function f. The function f then performs its computation and returns a next_effect.

  3. Log Aggregation: The logs from the incoming_effect are combined with the logs generated by the next_effect (from function f). 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

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,

Overrides the value within an effectful computation. Read more
Source§

impl MonadEffect3<CausalEffectSystem> for CausalMonad

Source§

fn pure<T>( value: T, ) -> <<CausalEffectSystem as Effect3>::HktWitness as HKT3<<CausalEffectSystem as Effect3>::Fixed1, <CausalEffectSystem as Effect3>::Fixed2>>::Type<T>

Lifts a pure value into the DSL’s Effect container (arity 3). Read more
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>

The core sequencing operation for arity 3 effect systems. Read more
Source§

impl<I, O, D, S, T, ST, SYM, VS, VT> MonadicCausable<CausalMonad> for Causaloid<I, O, D, S, T, ST, SYM, VS, VT>
where I: IntoEffectValue + Default, O: IntoEffectValue + Default, D: Datable + Clone, S: Spatial<VS> + Clone, T: Temporal<VT> + Clone, ST: SpaceTemporal<VS, VT> + Clone, SYM: Symbolic + Clone, VS: Clone, VT: Clone,

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

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 - The PropagatingEffect representing 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 monadic bind chain. 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 full PropagatingEffect (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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.