1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
use crate::;
/// The `Applicative` trait extends `Functor` and `Pure` by providing the `apply` operation
/// to apply a function wrapped in a context to a value wrapped in a context.
///
/// This trait is generic over `F`, which is a Higher-Kinded Type (HKT) witness.
///
/// # Hierarchy
///
/// `Applicative: Functor + Pure`
///
/// The `pure` operation is provided by the `Pure` trait, which is a supertrait.
/// This design allows `Monad` to share the same `pure` operation without requiring
/// `Monad: Applicative`.
///
/// # Constraint Support
///
/// The `apply` method requires types to satisfy the HKT's constraint.
/// This ensures type-safe application for constrained types.
///
/// # Laws (Informal)
///
/// 1. **Identity**: `apply(pure(id), v) == v`
/// 2. **Homomorphism**: `apply(pure(f), pure(x)) == pure(f(x))`
/// 3. **Interchange**: `apply(u, pure(y)) == apply(pure(|f| f(y)), u)`
///
/// # Type Parameters
///
/// * `F`: A Higher-Kinded Type (HKT) witness that represents the type constructor
/// (e.g., `OptionWitness`, `ResultWitness<E>`).