df5b76bd65
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>
2 lines
3.8 KiB
JSON
2 lines
3.8 KiB
JSON
{"defs":[{"ctors":[{"fields":[{"k":"var","name":"e"}],"name":"Left"},{"fields":[{"k":"var","name":"a"}],"name":"Right"}],"doc":"Disjoint sum: Left<e> for the failure branch, Right<a> for the success branch. Right is the conventional 'success' side.","kind":"type","name":"Either","vars":["e","a"]},{"body":{"arms":[{"body":{"name":"v","t":"var"},"pat":{"ctor":"Right","fields":[{"name":"v","p":"var"}],"p":"ctor"}},{"body":{"name":"default","t":"var"},"pat":{"ctor":"Left","fields":[{"p":"wild"}],"p":"ctor"}}],"scrutinee":{"name":"x","t":"var"},"t":"match"},"doc":"Project the Right<a> payload, or use the default for Left<_>.","kind":"fn","name":"from_right","params":["default","x"],"type":{"body":{"effects":[],"k":"fn","params":[{"k":"var","name":"a"},{"args":[{"k":"var","name":"e"},{"k":"var","name":"a"}],"k":"con","name":"Either"}],"ret":{"k":"var","name":"a"}},"k":"forall","vars":["e","a"]}},{"body":{"arms":[{"body":{"lit":{"kind":"bool","value":true},"t":"lit"},"pat":{"ctor":"Left","fields":[{"p":"wild"}],"p":"ctor"}},{"body":{"lit":{"kind":"bool","value":false},"t":"lit"},"pat":{"ctor":"Right","fields":[{"p":"wild"}],"p":"ctor"}}],"scrutinee":{"name":"x","t":"var"},"t":"match"},"doc":"Returns true iff x is Left<_>.","kind":"fn","name":"is_left","params":["x"],"type":{"body":{"effects":[],"k":"fn","params":[{"args":[{"k":"var","name":"e"},{"k":"var","name":"a"}],"k":"con","name":"Either"}],"ret":{"k":"con","name":"Bool"}},"k":"forall","vars":["e","a"]}},{"body":{"arms":[{"body":{"lit":{"kind":"bool","value":false},"t":"lit"},"pat":{"ctor":"Left","fields":[{"p":"wild"}],"p":"ctor"}},{"body":{"lit":{"kind":"bool","value":true},"t":"lit"},"pat":{"ctor":"Right","fields":[{"p":"wild"}],"p":"ctor"}}],"scrutinee":{"name":"x","t":"var"},"t":"match"},"doc":"Returns true iff x is Right<_>.","kind":"fn","name":"is_right","params":["x"],"type":{"body":{"effects":[],"k":"fn","params":[{"args":[{"k":"var","name":"e"},{"k":"var","name":"a"}],"k":"con","name":"Either"}],"ret":{"k":"con","name":"Bool"}},"k":"forall","vars":["e","a"]}},{"body":{"arms":[{"body":{"args":[{"args":[{"name":"v","t":"var"}],"fn":{"name":"f","t":"var"},"t":"app"}],"ctor":"Right","t":"ctor","type":"Either"},"pat":{"ctor":"Right","fields":[{"name":"v","p":"var"}],"p":"ctor"}},{"body":{"args":[{"name":"l","t":"var"}],"ctor":"Left","t":"ctor","type":"Either"},"pat":{"ctor":"Left","fields":[{"name":"l","p":"var"}],"p":"ctor"}}],"scrutinee":{"name":"x","t":"var"},"t":"match"},"doc":"Apply f to the Right<a> payload; pass Left<e> through untouched.","kind":"fn","name":"map_right","params":["f","x"],"type":{"body":{"effects":[],"k":"fn","params":[{"effects":[],"k":"fn","params":[{"k":"var","name":"a"}],"ret":{"k":"var","name":"b"}},{"args":[{"k":"var","name":"e"},{"k":"var","name":"a"}],"k":"con","name":"Either"}],"ret":{"args":[{"k":"var","name":"e"},{"k":"var","name":"b"}],"k":"con","name":"Either"}},"k":"forall","vars":["e","a","b"]}},{"body":{"arms":[{"body":{"args":[{"name":"l","t":"var"}],"fn":{"name":"on_left","t":"var"},"t":"app"},"pat":{"ctor":"Left","fields":[{"name":"l","p":"var"}],"p":"ctor"}},{"body":{"args":[{"name":"r","t":"var"}],"fn":{"name":"on_right","t":"var"},"t":"app"},"pat":{"ctor":"Right","fields":[{"name":"r","p":"var"}],"p":"ctor"}}],"scrutinee":{"name":"x","t":"var"},"t":"match"},"doc":"Eliminator: apply on_left to a Left payload, on_right to a Right payload, fold both branches into the same result type c.","kind":"fn","name":"either","params":["on_left","on_right","x"],"type":{"body":{"effects":[],"k":"fn","params":[{"effects":[],"k":"fn","params":[{"k":"var","name":"e"}],"ret":{"k":"var","name":"c"}},{"effects":[],"k":"fn","params":[{"k":"var","name":"a"}],"ret":{"k":"var","name":"c"}},{"args":[{"k":"var","name":"e"},{"k":"var","name":"a"}],"k":"con","name":"Either"}],"ret":{"k":"var","name":"c"}},"k":"forall","vars":["e","a","c"]}}],"imports":[],"name":"std_either","schema":"ailang/v0"}
|