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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
use Vec;
use crateCausalTensor;
use ;
// ============================================================================
// HKT Witness Implementation
// ============================================================================
/// The elementwise higher-kinded view of [`CausalTensor`].
///
/// This witness stands for the same container as [`CausalTensorWitness`](crate::CausalTensorWitness)
/// and differs only in what `apply` means. The two cannot be one witness, and the reason is a law
/// rather than a preference.
///
/// `CausalTensorWitness` carries [`Monad`](deep_causality_haft::Monad), which owes the
/// applicative/monad coherence law `apply(ff, fa) == bind(ff, |f| fmap(fa, f))`. `bind` runs the
/// continuation once per function, so coherence forces the *cartesian* applicative: every function
/// against every argument. That is the right answer for the monadic reading and the wrong one for
/// a tensor library, where applying a tensor of functions to a tensor of values elementwise is
/// what a caller means.
///
/// So the elementwise reading lives here, on the monoidal route. [`Semigroupal::zip_with`] pairs
/// slot with slot and consumes nothing twice, and [`MonoidalApplicative::apply`] is derived from
/// it. There is no `Monad` on this witness, so no coherence is owed and the two `apply`s are free
/// to differ.
///
/// # Why there is no `Pure` and no `LaxMonoidal`
///
/// The unit of a positional zip is the infinite repeat: the value that pairs with every element of
/// any tensor, at any shape. A finite `CausalTensor` cannot represent it. Anything else invented
/// for `unit` fails the unit laws at every non-matching shape rather than in some corner, so this
/// witness implements [`Semigroupal`] and stops there, exactly as
/// `deep_causality_haft::lax_monoidal` prescribes for a shape-carrying carrier.
///
/// [`CausalTensorWitness`]: crate::CausalTensorWitness
;