Iter 15d: std_either ships — 2-type-var ADT + 3-type-var eliminator
Third stdlib module. Either<e, a> is the first 2-type-var data def, and the eliminator `either : (e -> c) -> (a -> c) -> Either<e, a> -> c` the first fn with three type vars on top of the data — the deepest polymorphism shipped end-to-end so far. Five combinators: from_right, is_left, is_right, map_right, either. Demo exercises every one and runs to deterministic output. IR shows six distinct monomorphisations including two `from_right` variants (Left=Int vs Left=$u depending on call site) and `either__I_I_I`. No new compiler bugs surfaced: 14a / 14h / 15b coverage was wide enough to handle 2-type-var data plus 3-type-var fns out of the box. Discovered (queued as 15e): `ail render` and `ail parse` are not symmetric. Form-(A) printer in ailang_surface::print is the actual inverse of `parse` (round-trip test covers it across all 25 fixtures including std_either) but is not exposed via the CLI; `render` still calls the older ailang_core::pretty::module printer. Tests: 89/89 (was 88, +1 e2e for std_either_demo). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -305,6 +305,26 @@ fn std_list_stress_1000_element_folds() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Iter 15d: `std_either` end-to-end. First stdlib ADT with two type
|
||||
/// parameters (`Either<e, a>`); first combinator with three type vars
|
||||
/// (`either : (e -> c) -> (a -> c) -> Either<e, a> -> c`).
|
||||
///
|
||||
/// Property protected: monomorphisation correctly distinguishes per-
|
||||
/// call-site instantiations, including (a) two `from_right` instances
|
||||
/// differing only in the unused `e` (Int vs $u) and (b) the
|
||||
/// 3-type-var `either__I_I_I` instantiation. If wildcard substitution
|
||||
/// regressed, one of those would either fail to emit or collide with
|
||||
/// another instantiation.
|
||||
#[test]
|
||||
fn std_either_demo() {
|
||||
let stdout = build_and_run("std_either_demo.ail.json");
|
||||
let lines: Vec<&str> = stdout.lines().collect();
|
||||
assert_eq!(
|
||||
lines,
|
||||
vec!["42", "99", "true", "true", "42", "6", "101"]
|
||||
);
|
||||
}
|
||||
|
||||
/// Guards `ail diff`: a modified body changes the hash of `sum`, while
|
||||
/// `main` stays unchanged. Expects exit code 1, `changed` contains exactly
|
||||
/// `sum`, `unchanged` contains `main`, `added`/`removed` empty.
|
||||
|
||||
Reference in New Issue
Block a user