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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// =============================================================================
// Opt-in nightly acceleration (`nightly` cargo feature)
// =============================================================================
// The crate builds on stable Rust by default. The `nightly` feature enables
// unstable-Rust codegen improvements with identical semantics:
//
// - likely_unlikely: branch prediction hints (core::hint::likely/unlikely)
// used by `hints`; 10-15% improvement in hot paths per hashbrown benchmarks.
// On stable the hints are identity functions.
// - portable_simd (with `par`): core::simd vectorized f32 kernels in
// `par::simd`. On stable the same API is backed by scalar loops.
//! `OrdoFP` Core
//!
//! This library forms the core of `OrdoFP`. It should ideally be minimalistic,
//! containing only the fundamental building blocks of Universalis programming.
//!
//! # Examples
//!
//! ```
//! # use ordofp_core::hlist::*;
//! # use ordofp_core::{hlist, HList};
//! # fn main() {
//!
//! let h = hlist![1, false, 42f32];
//! let folded = h.foldr(hlist![|acc, i| i + acc,
//! |acc, _| if acc > 42f32 { 9000 } else { 0 },
//! |acc, f| f + acc],
//! 1f32);
//! assert_eq!(folded, 9001);
//!
//! // Reverse
//! let h1 = hlist![true, "hi"];
//! assert_eq!(h1.into_reverse(), hlist!["hi", true]);
//!
//! // foldr (foldl also available)
//! let h2 = hlist![1, false, 42f32];
//! let folded = h2.foldr(
//! hlist![|acc, i| i + acc,
//! |acc, _| if acc > 42f32 { 9000 } else { 0 },
//! |acc, f| f + acc],
//! 1f32
//! );
//! assert_eq!(folded, 9001);
//!
//! // Mapping over an HList
//! let h3 = hlist![9000, "joe", 41f32];
//! let mapped = h3.to_ref().map(hlist![|&n| n + 1,
//! |&s| s,
//! |&f| f + 1f32]);
//! assert_eq!(mapped, hlist![9001, "joe", 42f32]);
//!
//! // Plucking a value out by type
//! let h4 = hlist![1, "hello", true, 42f32];
//! let (t, remainder): (bool, _) = h4.pluck();
//! assert!(t);
//! assert_eq!(remainder, hlist![1, "hello", 42f32]);
//!
//! // Resculpting an HList
//! let h5 = hlist![9000, "joe", 41f32, true];
//! let (reshaped, remainder2): (HList![f32, i32, &str], _) = h5.sculpt();
//! assert_eq!(reshaped, hlist![41f32, 9000, "joe"]);
//! assert_eq!(remainder2, hlist![true]);
//! # }
//! ```
//!
//! Links:
//! 1. [Source on Github](https://github.com/ordokr/ordofp)
//! 2. [Crates.io page](https://crates.io/crates/ordofp)
extern crate std;
// NOTE: `alloc` is linked unconditionally; the `alloc` FEATURE gates API surface only. A true no-alloc core build is not currently supported.
extern crate alloc;
// Exported macros (e.g. `nonempty!`) must not assume the consumer crate
// declares `extern crate alloc`; this hidden re-export gives their expansions
// a `$crate`-anchored path to `alloc` items.
pub extern crate alloc as __alloc;
// Async module (OrdoFP 2.0)
// Requires the "async" feature flag
// Effects module (OrdoFP 2.0)
// Requires the "async" feature flag
// ParFlumen (data-parallel execution)
// Requires the "par" feature flag
// Nexus phase
// Requires the "nexus" feature flag (which implies "alloc")
// Linear types module (OrdoFP 3.0)
// Requires the "linear" feature flag
// Dependent types module (OrdoFP 3.0)
// Requires the "dependent" feature flag (implies "alloc")
// Recursion schemes module (OrdoFP 4.0)
// Requires the "alloc" feature flag
// Quantitative types module (OrdoFP 4.0 Phase 4)
// Requires the "quantitative" feature flag (implies "alloc"); pulled in by "async"
// Row polymorphism module (OrdoFP 4.0 Phase 5)
// Requires the "rows" feature flag (implies "alloc")
// Free monads and Tagless Final module (OrdoFP 4.0 Phase 6)
// Requires the "alloc" feature flag
// Category theory foundations module (OrdoFP 4.0 Phase 7)
// Requires the "alloc" feature flag
// Multiplicity / row-effect research modules
// FFI helper scaffolding — no callers in a pure-FP library,
// so gated off-by-default. Enable with the `ffi` feature.