deep_causality_haft/
effect.rs

1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6// ----------------------------------------------------
7// Effect Traits (Arity 3)
8// ----------------------------------------------------
9
10use crate::{HKT, HKT3, HKT4, HKT5};
11
12/// Effect3: The Bridge Trait for Arity 3 Type Constructors.
13///
14/// This trait is implemented by a user-defined **System Witness** (e.g., `MyEffect`)
15/// to partially apply (fix) two of the three generic parameters of an `HKT3` type.
16/// It serves as a crucial component in building type-encoded effect systems,
17/// allowing for the explicit tracking and handling of two fixed effect types
18/// (e.g., Error and Warning) while keeping the primary value type generic.
19pub trait Effect3 {
20    /// The fixed type for the first parameter of the `HKT3` type.
21    /// In many effect systems, this represents the Error type (e.g., `String`, `MyErrorStruct`).
22    type Fixed1;
23
24    /// The fixed type for the second parameter of the `HKT3` type.
25    /// This often represents a Warning or Log type (e.g., `String`, `Vec<String>`).
26    type Fixed2;
27
28    /// The concrete witness type that implements `HKT3` with the two fixed types (`Fixed1`, `Fixed2`).
29    /// This witness type *MUST* also implement `HKT` to be compatible with `Functor` and `Monad` traits.
30    /// It acts as a token to refer to the partially applied type constructor.
31    type HktWitness: HKT3<Self::Fixed1, Self::Fixed2> + HKT;
32}
33
34// ----------------------------------------------------
35// Effect Traits (Arity 4)
36// ----------------------------------------------------
37
38/// Effect4: The Bridge Trait for Arity 4 Type Constructors.
39///
40/// Similar to `Effect3`, this trait is implemented by a user-defined **System Witness**
41/// to partially apply (fix) three of the four generic parameters of an `HKT4` type.
42/// It is used for effect systems that need to track three distinct fixed effect types
43/// (e.g., Error, Warning, and a Counter) alongside the primary value type.
44pub trait Effect4 {
45    /// The fixed type for the first parameter of the `HKT4` type (e.g., an Error type).
46    type Fixed1;
47
48    /// The fixed type for the second parameter of the `HKT4` type (e.g., a Log type).
49    type Fixed2;
50
51    /// The fixed type for the third parameter of the `HKT4` type (e.g., a Counter type).
52    type Fixed3;
53
54    /// The concrete witness type that implements `HKT4` with the three fixed types (`Fixed1`, `Fixed2`, `Fixed3`).
55    /// This witness type *MUST* also implement `HKT` to be compatible with `Functor` and `Monad` traits.
56    type HktWitness: HKT4<Self::Fixed1, Self::Fixed2, Self::Fixed3> + HKT;
57}
58
59// ----------------------------------------------------
60// Effect Traits (Arity 5)
61// ----------------------------------------------------
62
63/// Effect5: The Bridge Trait for Arity 5 Type Constructors.
64///
65/// This trait is implemented by a user-defined **System Witness**
66/// to partially apply (fix) four of the five generic parameters of an `HKT5` type.
67/// It is designed for highly expressive effect systems that need to track four distinct fixed effect types
68/// (e.g., Error, Warning, Counter, and Trace information) alongside the primary value type.
69pub trait Effect5 {
70    /// The fixed type for the first parameter of the `HKT5` type (e.g., an Error type).
71    type Fixed1;
72
73    /// The fixed type for the second parameter of the `HKT5` type (e.g., a Log type).
74    type Fixed2;
75
76    /// The fixed type for the third parameter of the `HKT5` type (e.g., a Counter type).
77    type Fixed3;
78
79    /// The fixed type for the fourth parameter of the `HKT5` type (e.g., a Trace type).
80    type Fixed4;
81
82    /// The concrete witness type that implements `HKT5` with the four fixed types (`Fixed1`, `Fixed2`, `Fixed3`, `Fixed4`).
83    /// This witness type *MUST* also implement `HKT` to be compatible with `Functor` and `Monad` traits.
84    type HktWitness: HKT5<Self::Fixed1, Self::Fixed2, Self::Fixed3, Self::Fixed4> + HKT;
85}