CausalTensorWitness

Struct CausalTensorWitness 

Source
pub struct CausalTensorWitness;
Expand description

CausalTensorWitness is a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for the CausalTensor<T> type constructor. It allows CausalTensor to be used with generic functional programming traits like Functor, Applicative, Foldable, and Monad from the deep_causality_haft crate.

By implementing HKT for CausalTensorWitness, we can write generic functions that operate on any type that has the “shape” of CausalTensor, without knowing the inner type T.

Trait Implementations§

Source§

impl Applicative<CausalTensorWitness> for CausalTensorWitness

Source§

fn pure<T>(value: T) -> CausalTensor<T>

Lifts a pure value into a scalar CausalTensor.

§Arguments
  • value: The value to wrap in a CausalTensor.
§Returns

A new CausalTensor with a shape of [] containing the value.

Source§

fn apply<A, B, Func>( f_ab: CausalTensor<Func>, f_a: CausalTensor<A>, ) -> CausalTensor<B>
where Func: FnMut(A) -> B,

Applies a function wrapped in a CausalTensor (f_ab) to a value wrapped in a CausalTensor (f_a).

This implementation assumes f_ab is a scalar tensor containing a single function. It applies this function element-wise to all values in f_a.

§Arguments
  • f_ab: A CausalTensor containing a single function.
  • f_a: A CausalTensor containing arguments.
§Returns

A CausalTensor containing the results of applying the function to each value.

Source§

impl BoundedAdjunction<CausalTensorWitness, CausalTensorWitness, Vec<usize>> for CausalTensorWitness

Source§

fn left_adjunct<A, B, F>(ctx: &Vec<usize>, a: A, f: F) -> CausalTensor<B>
where F: Fn(CausalTensor<A>) -> B, A: Clone + Zero + Copy + PartialEq, B: Clone,

The Left Adjunct: $(L(A) \to B) \to (A \to R(B))$ Transforms a function on the “Left” structure to a function on the “Right” structure, using the provided context.
Source§

fn right_adjunct<A, B, F>(ctx: &Vec<usize>, la: CausalTensor<A>, f: F) -> B
where F: FnMut(A) -> CausalTensor<B>, A: Clone + Zero, B: Clone + Zero + Add<Output = B> + Mul<Output = B>,

The Right Adjunct: $(A \to R(B)) \to (L(A) \to B)$ Transforms a function on the “Right” structure to a function on the “Left” structure, using the provided context.
Source§

fn unit<A>(ctx: &Vec<usize>, a: A) -> CausalTensor<CausalTensor<A>>
where A: Clone + Zero + Copy + PartialEq,

The Unit of the Adjunction: $A \to R(L(A))$ Embeds a value into the Right-Left context, using the provided context.
Source§

fn counit<B>(_ctx: &Vec<usize>, lrb: CausalTensor<CausalTensor<B>>) -> B
where B: Clone + Zero + Add<Output = B> + Mul<Output = B>,

The Counit of the Adjunction: $L(R(B)) \to B$ Collapses the Left-Right context back to a value, using the provided context.
Source§

impl BoundedComonad<CausalTensorWitness> for CausalTensorWitness

Source§

fn extract<A>(fa: &CausalTensor<A>) -> A
where A: Clone,

Source§

fn extend<A, B, Func>(fa: &CausalTensor<A>, f: Func) -> CausalTensor<B>
where Func: FnMut(&CausalTensor<A>) -> B, A: Zero + Copy + Clone, B: Zero + Copy + Clone,

Source§

impl Foldable<CausalTensorWitness> for CausalTensorWitness

Source§

fn fold<A, B, Func>(fa: CausalTensor<A>, init: B, f: Func) -> B
where Func: FnMut(B, A) -> B,

Folds (reduces) a CausalTensor into a single value.

Applies the function f cumulatively to the elements of the tensor, starting with an initial accumulator value.

§Arguments
  • fa: The CausalTensor to fold.
  • init: The initial accumulator value.
  • f: The folding function.
§Returns

The accumulated result.

Source§

impl Functor<CausalTensorWitness> for CausalTensorWitness

Source§

fn fmap<A, B, Func>(m_a: CausalTensor<A>, f: Func) -> CausalTensor<B>
where Func: FnMut(A) -> B,

Implements the fmap operation for CausalTensor<T>.

Applies the function f to each element in the tensor, producing a new tensor.

§Arguments
  • m_a: The CausalTensor to map over.
  • f: The function to apply to each element.
§Returns

A new CausalTensor with the function applied to each of its elements.

Source§

impl HKT for CausalTensorWitness

Source§

type Type<T> = CausalTensor<T>

Specifies that CausalTensorWitness represents the CausalTensor<T> type constructor.

Source§

impl Monad<CausalTensorWitness> for CausalTensorWitness

Source§

fn bind<A, B, Func>(m_a: CausalTensor<A>, f: Func) -> CausalTensor<B>
where Func: FnMut(A) -> CausalTensor<B>,

Implements the bind (or flat_map) operation for CausalTensor<T>.

Applies the function f to each element in the tensor, where f itself returns a new CausalTensor. The data from all resulting tensors are then concatenated into a single 1-dimensional CausalTensor.

§Arguments
  • m_a: The initial CausalTensor.
  • f: A function that takes an inner value and returns a new CausalTensor.
§Returns

A new 1-dimensional CausalTensor representing the chained and flattened computation.

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.