Files
AILang/examples/std_either.ail
T
Brummel 72e54f4fd3 iter ext-rename: .ailx → .ail across the live toolchain
The surface-form file extension changes from .ailx to .ail. AILang's
authoring surface now uses the same .ail stem as its canonical JSON
form (.ail.json), giving the language a single coherent extension
family: .ail is the LLM-authored Form A, .ail.json is the canonical
JSON-AST Form B.

Scope (touched):
- 61 example renames examples/**/*.ailx → .ail (git mv)
- 1 rename experiments/.../rendered/ailx.md → ail.md
- 35 content-edited live-toolchain files (crates/, docs/DESIGN.md,
  docs/roadmap.md, docs/PROSE_ROUNDTRIP.md, skills/, bench/reference/*.c,
  experiment crates under experiments/.../{render,harness,master})
- Experiment-crate cohort rename Cohort::Ailx → Cohort::Ail,
  Form::Ailx → Form::Ail, per_cohort/ailx → per_cohort/ail,
  {form-only: ailx} → {form-only: ail}, ```ailx → ```ail

Out of scope (deliberately untouched, to preserve honest history):
- docs/journal-archive.md (content-frozen per CLAUDE.md)
- docs/journals/, docs/specs/, docs/plans/, bench/orchestrator-stats/
- experiments/.../runs/ (frozen LLM-output artefacts; models actually
  saw .ailx — renaming would falsify the experimental record)

Verification: cargo build/test --workspace green; experiment crate
cargo test green; bench/check.py + compile_check.py + cross_lang.py
all 0-regressed; negative grep for ailx|Ailx|AILX outside the
out-of-scope paths returns zero matches.

Opens immediate follow-up: roadmap.md P2 todo `ail check`/build/run
accept .ail extension — after this rename, .ail is canonical
authoring surface but the CLI still produces a misleading JSON-parse
error on `ail check foo.ail`. That's the next iter.
2026-05-12 14:20:27 +02:00

82 lines
2.3 KiB
Plaintext

; Iter 15d — third stdlib module: tagged-disjoint values.
; Either<e, a> is the canonical 2-type-var ADT. First stdlib module
; with two type parameters; first to ship an eliminator combinator
; (`either`) that introduces a third type var on top of the data.
(module std_either
(data Either (vars e a)
(doc "Disjoint sum: Left<e> for the failure branch, Right<a> for the success branch. Right is the conventional 'success' side.")
(ctor Left e)
(ctor Right a))
(fn from_right
(doc "Project the Right<a> payload, or use the default for Left<_>.")
(type
(forall (vars e a)
(fn-type
(params a (con Either e a))
(ret a))))
(params default x)
(body
(match x
(case (pat-ctor Right v) v)
(case (pat-ctor Left _) default))))
(fn is_left
(doc "Returns true iff x is Left<_>.")
(type
(forall (vars e a)
(fn-type
(params (con Either e a))
(ret (con Bool)))))
(params x)
(body
(match x
(case (pat-ctor Left _) true)
(case (pat-ctor Right _) false))))
(fn is_right
(doc "Returns true iff x is Right<_>.")
(type
(forall (vars e a)
(fn-type
(params (con Either e a))
(ret (con Bool)))))
(params x)
(body
(match x
(case (pat-ctor Left _) false)
(case (pat-ctor Right _) true))))
(fn map_right
(doc "Apply f to the Right<a> payload; pass Left<e> through untouched.")
(type
(forall (vars e a b)
(fn-type
(params (fn-type (params a) (ret b))
(con Either e a))
(ret (con Either e b)))))
(params f x)
(body
(match x
(case (pat-ctor Right v)
(term-ctor Either Right (app f v)))
(case (pat-ctor Left l)
(term-ctor Either Left l)))))
(fn either
(doc "Eliminator: apply on_left to a Left payload, on_right to a Right payload, fold both branches into the same result type c.")
(type
(forall (vars e a c)
(fn-type
(params (fn-type (params e) (ret c))
(fn-type (params a) (ret c))
(con Either e a))
(ret c))))
(params on_left on_right x)
(body
(match x
(case (pat-ctor Left l) (app on_left l))
(case (pat-ctor Right r) (app on_right r))))))