Design decisions

104. .map on fixed arrays [D]T / [D, E]T preserves index domains (2026-11-21)

  • Decision. .map(f) on a fixed array [D]T returns [D]U, and on a multi-dimensional fixed array [D, E]T returns [D, E]U (so nested [D][E]T preserves both domains through a.map(row => row.map(f))). List<T>, Str, Range<I>, Set/HashSet, Domain, and O(1) slices/views remain unchanged and return List<U>. All other element-wise/shape-preserving stdlib array operations (scan, suffix_scan, prev_less/next_less/prev_greater/next_greater, compose, inverse, perm_pow, copy) already return domain-typed arrays; reordering or length-changing ops (reversed, sorted, filter) stay List.
  • Why. Mapping over a domain-indexed array keeps a 1-to-1 correspondence with each index position, so dropping to List<U> threw away the domain proof and forced hand-written comprehensions (e.g., proto/ports/ecnerwala/dream/agc077a.cp:52, Block(seen.map(f), real.map(f)) with seen: [Side]Run failing with E0302).
  • Evidence. array_map_preserves_index_domain in crates/cpl-check/src/tests.rs, crates/cpl-cli/tests/programs/array_map.cp (interpreter + C++17 differential parity across 1D enum/domain/1-based-range/empty arrays, 2D [R, C]T, nested [Side][C]T, and unchanged List/Str/slices), and updated Array.map catalog row ([0..3]Int) passing builtin_catalog. Closes research/frictions/agc077a.md.
  • Reverse. Remove the Ty::Array arm for "map" in crates/cpl-check/src/check/call.rs, remove lower_array_map in crates/cpl-ir/src/lower/call.rs, and change the Array "map" row in crates/cpl-check/src/builtins.rs back to List<U>.