deep_causality_haft/effect_system/monad_effect_unbound.rs
1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6use crate::{
7 Effect3Unbound, Effect4Unbound, Effect5Unbound, HKT4Unbound, HKT5Unbound, HKT6Unbound,
8};
9
10// ----------------------------------------------------
11// Unbound Monad Effect Traits (Parametric Effects | Arity 3)
12// ----------------------------------------------------
13
14/// Monadic logic for Parametric Effects (Arity 3 Unbound).
15///
16/// Enables state transitions (`S1 -> S2`) within the effect system.
17pub trait MonadEffect3Unbound<E: Effect3Unbound> {
18 /// Lifts a pure value into the parametric effect container.
19 /// The state `S` remains unchanged (`S -> S`).
20 fn pure<S, T>(value: T) -> <E::HktWitness as HKT4Unbound>::Type<E::Fixed1, S, S, T>;
21
22 /// Indexed Bind: Chains computations while tracking state transitions.
23 /// `S1 -> S2` (first step) AND `S2 -> S3` (second step) => `S1 -> S3` (result).
24 fn ibind<S1, S2, S3, T, U, Func>(
25 effect: <E::HktWitness as HKT4Unbound>::Type<E::Fixed1, S1, S2, T>,
26 f: Func,
27 ) -> <E::HktWitness as HKT4Unbound>::Type<E::Fixed1, S1, S3, U>
28 where
29 Func: FnMut(T) -> <E::HktWitness as HKT4Unbound>::Type<E::Fixed1, S2, S3, U>;
30}
31
32// ----------------------------------------------------
33// Unbound Monad Effect Traits (Parametric Effects | Arity 4)
34// ----------------------------------------------------
35
36/// Monadic logic for Parametric Effects (Arity 4 Unbound).
37///
38/// Enables state transitions (`S1 -> S2`) within the effect system.
39#[allow(clippy::type_complexity)]
40pub trait MonadEffect4Unbound<E: Effect4Unbound> {
41 /// Lifts a pure value into the parametric effect container.
42 /// The state `S` remains unchanged (`S -> S`).
43 fn pure<S, T>(value: T) -> <E::HktWitness as HKT5Unbound>::Type<E::Fixed1, E::Fixed2, S, S, T>;
44
45 /// Indexed Bind: Chains computations while tracking state transitions.
46 fn ibind<S1, S2, S3, T, U, Func>(
47 effect: <E::HktWitness as HKT5Unbound>::Type<E::Fixed1, E::Fixed2, S1, S2, T>,
48 f: Func,
49 ) -> <E::HktWitness as HKT5Unbound>::Type<E::Fixed1, E::Fixed2, S1, S3, U>
50 where
51 Func: FnMut(T) -> <E::HktWitness as HKT5Unbound>::Type<E::Fixed1, E::Fixed2, S2, S3, U>;
52}
53
54// ----------------------------------------------------
55// Unbound Monad Effect Traits (Parametric Effects | Arity 5)
56// ----------------------------------------------------
57
58/// Monadic logic for Parametric Effects (Arity 5 Unbound).
59///
60/// Enables state transitions (`S1 -> S2`) within the effect system.
61#[allow(clippy::type_complexity)]
62pub trait MonadEffect5Unbound<E: Effect5Unbound> {
63 /// Lifts a pure value into the parametric effect container.
64 /// The state `S` remains unchanged (`S -> S`).
65 fn pure<S, T>(
66 value: T,
67 ) -> <E::HktWitness as HKT6Unbound>::Type<E::Fixed1, E::Fixed2, E::Fixed3, S, S, T>;
68
69 /// Indexed Bind: Chains computations while tracking state transitions.
70 fn ibind<S1, S2, S3, T, U, Func>(
71 effect: <E::HktWitness as HKT6Unbound>::Type<E::Fixed1, E::Fixed2, E::Fixed3, S1, S2, T>,
72 f: Func,
73 ) -> <E::HktWitness as HKT6Unbound>::Type<E::Fixed1, E::Fixed2, E::Fixed3, S1, S3, U>
74 where
75 Func: FnMut(
76 T,
77 ) -> <E::HktWitness as HKT6Unbound>::Type<
78 E::Fixed1,
79 E::Fixed2,
80 E::Fixed3,
81 S2,
82 S3,
83 U,
84 >;
85}