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
63
64
65
66
67
68
69
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
use crate::;
/// The `Functor` trait abstracts over types that can be mapped over.
///
/// It provides the `fmap` operation, which applies a function to the value
/// inside a type constructor, preserving the structure of the type.
///
/// This trait is generic over `F`, which is a Higher-Kinded Type (HKT) witness.
///
/// # Constraint Support
///
/// The `fmap` function now requires both input type `A` and output type `B`
/// to satisfy the HKT's constraint. This ensures type-safe mapping for
/// constrained types like `CausalTensor<T>` where `T: TensorData`.
///
/// # Laws (Informal)
///
/// 1. **Identity**: `fmap(id, fa) == fa`
/// 2. **Composition**: `fmap(f.compose(g), fa) == fmap(f, fmap(g, fa))`
///
/// # Type Parameters
///
/// * `F`: A Higher-Kinded Type (HKT) witness that represents the type constructor
/// (e.g., `OptionWitness`, `ResultWitness<E>`, `VecWitness`).