Expand description
The deep_causality_haft crate provides foundational traits and utilities for
implementing Higher-Kinded Types (HKTs) and functional programming patterns
(Functor, Applicative, Monad, Foldable) in Rust.
This crate is a core component of the deep_causality project, enabling
the construction of flexible and robust type-encoded effect systems.
§Core Concepts
- Higher-Kinded Types (HKTs): Abstractions over type constructors (e.g.,
Option<T>,Vec<T>). This allows writing generic code that works across different container types. - Functor: Defines the
fmapoperation for mapping a function over a type constructor. - Applicative: Extends
Functorwithpure(to lift values) andapply(to apply functions within a context). - Monad: Provides the
bindoperation for sequencing computations that produce effectful values. - Foldable: Defines the
foldoperation for reducing a data structure to a single value. - Type-Encoded Effect Systems: A mechanism to explicitly track and manage side-effects (like errors, logging, counters) using Rust’s type system, ensuring compile-time verification.
§Modules
core: Core HKT definitions and machinery.algebra: Algebraic traits (Functor, Monad, etc.).effect_system: Type-encoded effect system traits.extensions: Concrete HKT witness implementations for standard Rust types.utils_tests: Internal utilities and test-specific effect types.
§Usage
This crate is primarily intended for internal use within the deep_causality project
to build its core abstractions. However, the traits and concepts can be generally applied
to other Rust projects requiring advanced functional programming patterns and effect management.
Modules§
- utils_
tests - This module provides utility types and implementations primarily used for testing
and demonstrating the type-encoded effect system within
deep_causality_haft.
Structs§
- BTree
MapWitness BTreeMapWitness<K>is a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for theBTreeMap<K, V>type constructor, where the key typeKis fixed.- BoxWitness
BoxWitnessis a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for theBox<T>type constructor. It allowsBoxto be used with generic functional programming traits likeFunctor,Applicative,Foldable, andMonad.- Hash
MapWitness HashMapWitness<K>is a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for theHashMap<K, V>type constructor, where the key typeKis fixed.- Linked
List Witness LinkedListWitnessis a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for theLinkedList<T>type constructor. It allowsLinkedListto be used with generic functional programming traits likeFunctor,Applicative,Foldable, andMonad.- Option
Witness OptionWitnessis a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for theOption<T>type constructor. It allowsOptionto be used with generic functional programming traits likeFunctor,Applicative,Foldable, andMonad.- Placeholder
- A zero-sized type used purely as a marker or placeholder when implementing Higher-Kinded Type (HKT) traits for concrete types.
- Result
Unbound Witness ResultUnboundWitnessis a zero-sized type that acts as a witness for theResult<A, B>type constructor where both parameters are unbound.- Result
Witness ResultWitness<E>is a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for theResult<T, E>type constructor, where the error typeEis fixed.- Tuple2
Witness Tuple2Witnessacts as a witness for the(A, B)type constructor.- Tuple3
Witness Tuple3Witnessacts as a witness for the(A, B, C)type constructor.- VecDeque
Witness VecDequeWitnessis a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for theVecDeque<T>type constructor. It allowsVecDequeto be used with generic functional programming traits likeFunctorandFoldable.- VecWitness
VecWitnessis a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for theVec<T>type constructor. It allowsVecto be used with generic functional programming traits likeFunctor,Applicative,Foldable, andMonad.
Traits§
- Adjunction
- The
Adjunctiontrait defines a pair of adjoint functors $L$ (Left) and $R$ (Right). - Applicative
- The
Applicativetrait extendsFunctorby providing methods to apply a function wrapped in a context to a value wrapped in a context, and to lift a pure value into the minimal context. - Bifunctor
- The
Bifunctortrait allows mapping over both arguments of a type constructorF<A, B>. - Bounded
Adjunction - The
BoundedAdjunctiontrait defines a pair of adjoint functors $L$ (Left) and $R$ (Right) that require a runtimeContextto operate. - Bounded
Comonad - A Comonad that requires its contents to satisfy algebraic bounds. Essential for structures like MultiVectors that need a ‘Zero’ to represent a Physical Field Operator.
- CoMonad
- The
CoMonadtrait represents a comonadic context, which is the dual of aMonad. - Cybernetic
Loop - The
CyberneticLooptrait models a complete feedback control system involving 5 distinct components. - Effect3
- Effect3: The Bridge Trait for Arity 3 Type Constructors.
- Effect4
- Effect4: The Bridge Trait for Arity 4 Type Constructors.
- Effect5
- Effect5: The Bridge Trait for Arity 5 Type Constructors.
- Effect3
Unbound - Effect3Unbound: Parametric Effect Trait for Arity 3.
- Effect4
Unbound - Effect4Unbound: Parametric Effect Trait for Arity 4.
- Effect5
Unbound - Effect5Unbound: Parametric Effect Trait for Arity 5.
- Foldable
- The
Foldabletrait abstracts over data structures that can be reduced to a single summary value. - Functor
- The
Functortrait abstracts over types that can be mapped over. - HKT
- Trait for a Higher-Kinded Type (HKT) with one type parameter (arity 1).
- HKT2
- Trait for a Higher-Kinded Type (HKT) with two type parameters (arity 2).
- HKT3
- Trait for a Higher-Kinded Type (HKT) with three type parameters (arity 3).
- HKT4
- Trait for a Higher-Kinded Type (HKT) with four type parameters (arity 4).
- HKT5
- Trait for a Higher-Kinded Type (HKT) with five type parameters (arity 5).
- HKT2
Unbound - Trait for a Higher-Kinded Type (HKT) with two unbound generic parameters (Arity 2).
- HKT3
Unbound - Trait for a Higher-Kinded Type (HKT) with three unbound generic parameters (Arity 3).
- HKT4
Unbound - Trait for a Higher-Kinded Type (HKT) with four unbound generic parameters (Arity 4).
- HKT5
Unbound - Trait for a Higher-Kinded Type (HKT) with five unbound generic parameters (Arity 5).
- HKT6
Unbound - Trait for a Higher-Kinded Type (HKT) with six unbound generic parameters (Arity 6).
- LogAdd
Entry - LogAppend
- Trait for types that can append log entries from another instance of themselves.
- LogEffect
- LogSize
- Monad
- The
Monadtrait extendsApplicativeby providing abindoperation for sequencing computations that produce effectful values. - Monad
Effect3 - Monadic logic for an Arity 3 type after it has been partially applied via
Effect3. - Monad
Effect4 - Monadic logic for an Arity 4 type after it has been partially applied via
Effect4. - Monad
Effect5 - Monadic logic for an Arity 5 type after it has been partially applied via
Effect5. - Monad
Effect3 Unbound - Monadic logic for Parametric Effects (Arity 3 Unbound).
- Monad
Effect4 Unbound - Monadic logic for Parametric Effects (Arity 4 Unbound).
- Monad
Effect5 Unbound - Monadic logic for Parametric Effects (Arity 5 Unbound).
- Parametric
Monad - The
ParametricMonad(or Indexed Monad) trait allows for monadic computations where the type of the underlying state can change at each step. - Profunctor
- The
Profunctortrait represents a type constructor that is contravariant in its first argument and covariant in its second argument. - Promonad
- The
Promonadtrait models the “fusion” or “interaction” of two contexts to produce a third. - Riemann
Map - The
RiemannMaptrait models high-arity geometric interactions, specifically the Riemann Curvature Tensor and Scattering Matrices. - Traversable
- The
Traversabletrait abstracts over data structures that can be “traversed” or “sequenced” in a way that preserves effects. It combines the capabilities ofFunctor(mapping over elements) andFoldable(reducing to a single value).