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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
use crate::;
use vec;
use Vec;
/// `VecWitness` is a zero-sized type that acts as a Higher-Kinded Type (HKT) witness
/// for the `Vec<T>` type constructor. It allows `Vec` to be used with generic
/// functional programming traits like `Functor`, `Applicative`, `Foldable`, and `Monad`.
///
/// By implementing `HKT` for `VecWitness`, we can write generic functions that operate
/// on any type that has the "shape" of `Vec`, without knowing the inner type `T`.
///
/// # Element bounds
///
/// `VecWitness` places no bound on `T`.
;
// Implementation of Pure for VecWitness
// Implementation of Applicative for VecWitness
// Implementation of Functor for VecWitness
// Implementation of Foldable for VecWitness
// Implementation of Monad for VecWitness
// Implementation of EqFunctor for VecWitness (element-wise structural equality of `Vec<T>`).
// Implementation of DebugFunctor for VecWitness (delegates to `Vec`'s own `Debug`).
// Implementation of CloneFunctor for VecWitness (delegates to `Vec`'s own `Clone`).
// NOTE: `Traversable` is deliberately not implemented for `VecWitness`, and the reason is a
// signature one rather than a mathematical one.
//
// The usual `sequence` for a list folds an accumulator through the inner applicative:
//
// acc = M::apply(M::fmap(acc, |v| move |a| { v.push(a); v }), m_a)
//
// That puts a *function* inside `M`. When the trait carried an element marker, `Applicative::apply`
// required the anonymous closure type to satisfy it, `sequence` could not declare that, and an impl
// could not add the bound itself (E0276). The marker is gone, so that particular obstruction is
// gone with it. The fold written against a `zip_with`-style structure map remains the better form,
// because the combining function never enters `M` at all:
//
// acc = M::zip_with(acc, m_a, |mut v, a| { v.push(a); v });
//
// The `zip_with` structure map now exists (`crate::Semigroupal`), and a `sequence` written
// against it does compile and pass. It is still not implemented here, and that is a decision
// rather than an omission: `sequence`'s inner-`M` bound would have to move from `Applicative` to
// `Semigroupal + Pure`, and those two are substitutive rather than comparable. Measured, that
// swap takes the witnesses admissible as the inner applicative from 19 down to 3, losing every
// effect monad in the workspace — `StudyEffectWitness`, `CdlEffectWitness`,
// `GraphGeneratableEffectWitness` and the `MyEffectHktWitness` family — along with `BoxWitness`,
// `LinkedListWitness`, `ManifoldWitness`, `CausalTensorWitness` and `VecWitness` itself. One
// carrier gained is not worth sixteen lost.
//
// Revisit only as part of a change that first adopts `Semigroupal` across those witnesses, so the
// bound can move without narrowing the trait's contract. See
// `openspec/notes/archive/hkt_gat/monoidal-applicative.md` §6 finding 5 for the measurement. Until then,
// `OptionWitness` and `ResultWitness` are the only two `Traversable` carriers.