✓
Passing This code compiles and runs correctly.
Code
// Multi-arm resume sum ("effects having effects → sessions"): an effect
// branch's OUTPUT generalizes from the single anonymous `-> T` resume
// (cf. 400_085 `! double i32 -> i32`) to a flat SUM of named arms. Here
// `! ask` yields an i32 and the handler resumes by SELECTING one arm with
// `=>` — `| halved i32` or `| timeout`. You never nest `!`; the composition
// lives in the `|` arm tree. Grammar pinned in 210_092 (indented) and
// 210_093 (single-line).
//
// The resume-by-named-arm spelling (`=> halved v`) reuses the existing
// branch-ctor resume grammar (cf. the subflow resume `greet => greeting "..."`
// in 020_014), now in effect-resume position. Glyph discipline holds: this
// effect HAS arms, so `=>` constructs one (`->` is the single-resume producer
// and is illegal here).
//
// The `proc` consumes the multi-arm resume as a TAGGED UNION — the same way
// it binds a scalar from a `-> T` effect today, `const r = ask(payload)`
// binds the synthesized `union(enum) { halved: i32, timeout: void }` and the
// proc dispatches with an ordinary Zig `switch`.
~import std/io
~pub tor request { payload: i32 }
! ask i32
| halved i32
| timeout
| done i32
~proc request|zig {
const r = ask(payload);
return switch (r) {
.halved => |v| .{ .done = v },
.timeout => .{ .done = -1 },
};
}
~request(payload: 20)
! ask n => halved @divTrunc(n, 2)
| done r |> std/io:print.ln("{{ r:d }}")
Actual
10
Expected output
10
Flows
flow ~request click a branch to expand · @labels scroll to their anchor
request (payload: 20)
Test Configuration
MUST_RUN