Skip to content

Commit c2e4121

Browse files
fix(stdlib): module visibility + imports per ADR-011 (#135 slice 8) (#164)
#135 slice 8 — bring the remaining core stdlib under the ADR-011 module model so `use prelude::{…}` actually resolves: - prelude.affine: its public API is now `pub` (types Option/Result + the 14 list/numeric utilities). Previously non-`pub`, so importing modules hit `Resolve.VisibilityError` on `Result`/etc. - result.affine / option.affine: extend `use prelude::{…}` with `map` (both call prelude's `map`); was `UndefinedVariable map`. - collections.affine: add `module collections;` + `use prelude::{Option, Some, None, filter, map, range, any}` (had no module/use — pre-#133 flat-namespace assumption). - result.affine `try_map`: `map(f, list)` -> `map(list, f)` — genuine stdlib bug (prelude `map` is `map(arr, f)`; arg order was swapped, surfaced as a function-vs-`[T]` type error once imports resolved). Result: **prelude.affine compiles end-to-end**; result/option/ collections clear ALL import-resolution (VisibilityError/ImportError gone). result now reaches typecheck; collections reaches a *distinct* pre-existing defect — the resolver has no forward-reference support between top-level fns (`binary_search` → `binary_search_helper`), reproducible even without `module`; that is a new resolver slice, not slice 8. io still needs cross-module `split` (in string.affine) — slice 8 tail. Full suite green (230); no regression. Advances #135. Refs #128, #135. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e950dbc commit c2e4121

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

stdlib/collections.affine

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
//
44
// Collections - Advanced list, array, and data structure operations
55

6+
module collections;
7+
8+
// `Option` + constructors and the generic list utilities are owned by
9+
// `prelude` (ADR-011); collections is a consumer module (#135 slice 8).
10+
use prelude::{Option, Some, None, filter, map, range, any};
11+
612
// ============================================================================
713
// List Operations
814
// ============================================================================

stdlib/option.affine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module option;
77

88
// `Option`/`Result` types + constructors are owned by `prelude` (ADR-011).
9-
use prelude::{Option, Some, None, Result, Ok, Err};
9+
use prelude::{Option, Some, None, Result, Ok, Err, map};
1010

1111
// This module is the single canonical home for the Option *operations*
1212
// (is_some/is_none/unwrap/unwrap_or/map/filter/contains/…). #133 removed

stdlib/prelude.affine

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ module prelude;
1616
// the single canonical bindings for those.
1717
// ============================================================================
1818

19-
type Option<T> = Some(T) | None
19+
pub type Option<T> = Some(T) | None
2020

21-
type Result<T, E> = Ok(T) | Err(E)
21+
pub type Result<T, E> = Ok(T) | Err(E)
2222

2323
// ============================================================================
2424
// List utilities
2525
// ============================================================================
2626

27-
fn map<T, U>(arr: [T], f: T -> U) -> [U] {
27+
pub fn map<T, U>(arr: [T], f: T -> U) -> [U] {
2828
let mut result = [];
2929
for x in arr {
3030
result = result ++ [f(x)];
3131
}
3232
result
3333
}
3434

35-
fn filter<T>(arr: [T], predicate: T -> Bool) -> [T] {
35+
pub fn filter<T>(arr: [T], predicate: T -> Bool) -> [T] {
3636
let mut result = [];
3737
for x in arr {
3838
if predicate(x) {
@@ -42,7 +42,7 @@ fn filter<T>(arr: [T], predicate: T -> Bool) -> [T] {
4242
result
4343
}
4444

45-
fn fold<T, U>(arr: [T], init: U, f: (U, T) -> U) -> U {
45+
pub fn fold<T, U>(arr: [T], init: U, f: (U, T) -> U) -> U {
4646
let mut acc = init;
4747
for x in arr {
4848
acc = f(acc, x);
@@ -51,7 +51,7 @@ fn fold<T, U>(arr: [T], init: U, f: (U, T) -> U) -> U {
5151
}
5252

5353
/// Conforms to aLib collection/contains spec v1.0
54-
fn contains<T>(arr: [T], element: T) -> Bool {
54+
pub fn contains<T>(arr: [T], element: T) -> Bool {
5555
for x in arr {
5656
if x == element {
5757
return true;
@@ -60,27 +60,27 @@ fn contains<T>(arr: [T], element: T) -> Bool {
6060
false
6161
}
6262

63-
fn sum(arr: [Int]) -> Int {
63+
pub fn sum(arr: [Int]) -> Int {
6464
fold(arr, 0, |acc, x| acc + x)
6565
}
6666

67-
fn product(arr: [Int]) -> Int {
67+
pub fn product(arr: [Int]) -> Int {
6868
fold(arr, 1, |acc, x| acc * x)
6969
}
7070

7171
// ============================================================================
7272
// Comparison and ordering
7373
// ============================================================================
7474

75-
fn min(a: Int, b: Int) -> Int {
75+
pub fn min(a: Int, b: Int) -> Int {
7676
if a < b { a } else { b }
7777
}
7878

79-
fn max(a: Int, b: Int) -> Int {
79+
pub fn max(a: Int, b: Int) -> Int {
8080
if a > b { a } else { b }
8181
}
8282

83-
fn clamp(value: Int, min_val: Int, max_val: Int) -> Int {
83+
pub fn clamp(value: Int, min_val: Int, max_val: Int) -> Int {
8484
if value < min_val {
8585
min_val
8686
} else if value > max_val {
@@ -94,11 +94,11 @@ fn clamp(value: Int, min_val: Int, max_val: Int) -> Int {
9494
// Boolean utilities
9595
// ============================================================================
9696

97-
fn not(b: Bool) -> Bool {
97+
pub fn not(b: Bool) -> Bool {
9898
if b { false } else { true }
9999
}
100100

101-
fn all(arr: [Bool]) -> Bool {
101+
pub fn all(arr: [Bool]) -> Bool {
102102
for b in arr {
103103
if not(b) {
104104
return false;
@@ -107,7 +107,7 @@ fn all(arr: [Bool]) -> Bool {
107107
true
108108
}
109109

110-
fn any(arr: [Bool]) -> Bool {
110+
pub fn any(arr: [Bool]) -> Bool {
111111
for b in arr {
112112
if b {
113113
return true;
@@ -120,7 +120,7 @@ fn any(arr: [Bool]) -> Bool {
120120
// Range and iteration utilities
121121
// ============================================================================
122122

123-
fn range(start: Int, end: Int) -> [Int] {
123+
pub fn range(start: Int, end: Int) -> [Int] {
124124
let mut result = [];
125125
let mut i = start;
126126
while i < end {
@@ -130,7 +130,7 @@ fn range(start: Int, end: Int) -> [Int] {
130130
result
131131
}
132132

133-
fn repeat<T>(value: T, n: Int) -> [T] {
133+
pub fn repeat<T>(value: T, n: Int) -> [T] {
134134
let mut result = [];
135135
let mut i = 0;
136136
while i < n {

stdlib/result.affine

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module result;
77

88
// `Option`/`Result` types + constructors are owned by `prelude` (ADR-011).
9-
use prelude::{Result, Ok, Err, Option, Some, None};
9+
use prelude::{Result, Ok, Err, Option, Some, None, map};
1010

1111
// This module is the single canonical home for the Result *operations*
1212
// (is_ok/is_err/unwrap/unwrap_or/map_ok/map_err/…). #133 removed the
@@ -187,7 +187,7 @@ fn partition_results<T, E>(results: [Result<T, E>]) -> ([T], [E]) {
187187

188188
/// Try to apply function to all elements, collecting errors
189189
fn try_map<T, U, E>(f: T -> Result<U, E>, list: [T]) -> Result<[U], E> {
190-
let results = map(f, list);
190+
let results = map(list, f);
191191
collect(results)
192192
}
193193

0 commit comments

Comments
 (0)