Commit a921dce
feat(stdlib): async sequencing combinators + declare Async effect (Refs echidna#62)
Adds stdlib/future.affine and declares `effect Async;` in
stdlib/effects.affine — the async primitive for the
ReScript->AffineScript migration (echidna#62; Client.res's
`promise<result<T, string>>` chains via Promise.then/catch/resolve).
Model (thin combinators over Result + effect; user-chosen approach):
on the Deno-ESM target the compiler emits native JS async/await and
host promises cross as the Thenable extern ABI (#103) — suspension is
at the extern boundary (echidna#61 Http), so the source needs no
promise monad. An async value is its settled `Result<T, String>`
(Client.res's `result<_, string>`), carried by an `/{Async}`-effect
function. future.affine is the value-level half: a 1:1 map of the
ReScript promise chain onto that Result.
No wrapper type by necessity, not just preference: a user-defined
generic `Async<T>` (ADT or alias) is unusable in signatures — the
typechecker raises "Too many arguments for kind"; only prelude's
multi-constructor `Option`/`Result` are sound generic carriers. This
is a real AffineScript compiler limitation (single-constructor /
aliased generic types) — recorded for a follow-up affinescript issue.
`Result<T, String>` is also exactly Client.res's existing shape.
Surface: resolve (Promise.resolve) / reject / then (Promise.then,
async step) / map_ok (then with pure mapper) / recover (Promise.catch)
/ map_err. effects.affine now declares `effect Async;` (the #196 v1
registry already reserved the name; Vscode.affine already used
`/ Async` — this closes the stdlib coherence gap).
Verified: #136 stdlib-wide AOT smoke gate drives the new file +
modified effects.affine through resolve -> typecheck -> borrow ->
Deno-ESM codegen; `dune runtest` green incl. new "AOT future.affine"
case and unchanged "AOT effects.affine". Regression-protected on merge.
echidna#62 stays open as the consumer-side tracker per its protocol
(closes when the Client.res port lands, not here). Independent of
echidna#63/#64 (no code import) — independent PR off main. Next: #61
http.affine (Deno fetch extern -> the /{Async} boundary; where the
String->Json parse bridge lands).
Refs #128, hyperpolymath/echidna#62.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent efa0339 commit a921dce
2 files changed
Lines changed: 99 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
0 commit comments