Files
AILang/examples/std_either_demo.ail.json
T
Brummel df5b76bd65 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>
2026-05-07 18:48:43 +02:00

2 lines
2.6 KiB
JSON

{"defs":[{"body":{"args":[{"name":"x","t":"var"},{"lit":{"kind":"int","value":1},"t":"lit"}],"fn":{"name":"+","t":"var"},"t":"app"},"doc":"Add 1 to an Int. Used as the function arg to map_right and either.","kind":"fn","name":"inc","params":["x"],"type":{"effects":[],"k":"fn","params":[{"k":"con","name":"Int"}],"ret":{"k":"con","name":"Int"}}},{"body":{"lhs":{"args":[{"args":[{"lit":{"kind":"int","value":0},"t":"lit"},{"args":[{"lit":{"kind":"int","value":42},"t":"lit"}],"ctor":"Right","t":"ctor","type":"std_either.Either"}],"fn":{"name":"std_either.from_right","t":"var"},"t":"app"}],"op":"io/print_int","t":"do"},"rhs":{"lhs":{"args":[{"args":[{"lit":{"kind":"int","value":99},"t":"lit"},{"args":[{"lit":{"kind":"int","value":7},"t":"lit"}],"ctor":"Left","t":"ctor","type":"std_either.Either"}],"fn":{"name":"std_either.from_right","t":"var"},"t":"app"}],"op":"io/print_int","t":"do"},"rhs":{"lhs":{"args":[{"args":[{"args":[{"lit":{"kind":"int","value":7},"t":"lit"}],"ctor":"Left","t":"ctor","type":"std_either.Either"}],"fn":{"name":"std_either.is_left","t":"var"},"t":"app"}],"op":"io/print_bool","t":"do"},"rhs":{"lhs":{"args":[{"args":[{"args":[{"lit":{"kind":"int","value":42},"t":"lit"}],"ctor":"Right","t":"ctor","type":"std_either.Either"}],"fn":{"name":"std_either.is_right","t":"var"},"t":"app"}],"op":"io/print_bool","t":"do"},"rhs":{"lhs":{"args":[{"args":[{"lit":{"kind":"int","value":0},"t":"lit"},{"args":[{"name":"inc","t":"var"},{"args":[{"lit":{"kind":"int","value":41},"t":"lit"}],"ctor":"Right","t":"ctor","type":"std_either.Either"}],"fn":{"name":"std_either.map_right","t":"var"},"t":"app"}],"fn":{"name":"std_either.from_right","t":"var"},"t":"app"}],"op":"io/print_int","t":"do"},"rhs":{"lhs":{"args":[{"args":[{"name":"inc","t":"var"},{"name":"inc","t":"var"},{"args":[{"lit":{"kind":"int","value":5},"t":"lit"}],"ctor":"Left","t":"ctor","type":"std_either.Either"}],"fn":{"name":"std_either.either","t":"var"},"t":"app"}],"op":"io/print_int","t":"do"},"rhs":{"args":[{"args":[{"name":"inc","t":"var"},{"name":"inc","t":"var"},{"args":[{"lit":{"kind":"int","value":100},"t":"lit"}],"ctor":"Right","t":"ctor","type":"std_either.Either"}],"fn":{"name":"std_either.either","t":"var"},"t":"app"}],"op":"io/print_int","t":"do"},"t":"seq"},"t":"seq"},"t":"seq"},"t":"seq"},"t":"seq"},"t":"seq"},"doc":"Drive each std_either combinator. Expected outputs (per line): 42, 99, true, true, 42, 6, 101.","kind":"fn","name":"main","params":[],"type":{"effects":["IO"],"k":"fn","params":[],"ret":{"k":"con","name":"Unit"}}}],"imports":[{"module":"std_either"}],"name":"std_either_demo","schema":"ailang/v0"}