| @@ -0,0 +1,54 @@ |
| 1 | +# ADR 0044: Effect-row ergonomics: row aliases and the `/_>` marker |
| 2 | + |
| 3 | +**Status:** Proposed (2026-10-15, issue #203); needs engineering review (#44). It adds a declaration form and relaxes a signature rule, so it changes what the language accepts — the type checker keeps the same rows underneath. |
| 4 | + |
| 5 | +## Context |
| 6 | +Effect rows keep Louise's guarantees visible, but they are verbose in a way that grows with an app. The `examples/http_demo` (587 lines) shows three distinct pains, analysed in the issue: |
| 7 | + |
| 8 | +1. **Row repetition.** The same rows repeat across sibling functions — the demo writes `<proc, random, io, ffi>` five times in `store.lse` alone. Adding or dropping an effect means editing every site. |
| 9 | +2. **Handler-wrapper plumbing.** `with_store(db, action: fn() -> a / <users, proc | e>) -> a / <proc | e>`: the handled effect is listed in the parameter's row, the clauses' own effects in the wrapper's row, and `e` threads through both. This tax is paid per wrapper, and wrappers multiply as an app grows. |
| 10 | +3. **Order noise.** Rows are sets (scoped duplicates aside, ADR 0008), yet the demo writes `<io, proc, ffi>` in one place and `<proc, random, io, ffi>` in another — nothing to learn from the difference, everything to scan. (The `W0501` dead-member lint, option A, already keeps rows honest as documentation; canonical order is a separate, smaller thing.) |
| 11 | + |
| 12 | +What is already true and shapes the options: a function with **no signature at all** gets its row inferred; a signature with a result type but **no row means total** (E0502 otherwise) — that default is a feature, it catches effects you didn't mean to perform; `pub fn` requires a complete signature, API stability doing its job. |
| 13 | + |
| 14 | +## Decision |
| 15 | + |
| 16 | +Two independent features, both leaving the type system's rows untouched. |
| 17 | + |
| 18 | +### B: row aliases |
| 19 | +A new declaration form names a set of effects once: |
| 20 | + |
| 21 | +```text |
| 22 | +pub effect alias app = proc, random, io, ffi |
| 23 | +``` |
| 24 | + |
| 25 | +and a row may name it where a label goes: `-> () / <app>`, `-> () / <app | e>`, in a parameter's row too (`fn() -> a / <users, app | e>`). The alias **expands to its members** at name resolution: `<app | e>` *is* `<proc, random, io, ffi | e>`, so no typing rule changes — unification, subsumption and the `W0501` lint see the expanded row. Aliases may not be recursive, may not take parameters (v1), and a member that is itself an alias expands transitively (a set, so duplicates collapse). |
| 26 | + |
| 27 | +Risks: indirection (a reader must know the alias; the LSP's hover expands it — noted as follow-up work); aliases outgrowing their uses (the dead-member lint gets coarser through an alias: it reports a member dead in the alias even where it is live in some other use — flagged here so review can weigh it). |
| 28 | + |
| 29 | +### C: the `/_>` marker |
| 30 | +A signature with a result type but **no row means total** today. `/_>` keeps the rest of the signature explicit and infers only the row: |
| 31 | + |
| 32 | +```text |
| 33 | +fn with_store(db, action: fn() -> a / <users, proc | e>) -> a / <_> |
| 34 | +``` |
| 35 | + |
| 36 | +The body runs with the row a fresh unification variable that the body's effects fill (the same machinery that infers the whole row of a signature-less private function, ADR 0008); at generalisation the variable becomes a scheme row variable if it is still free — `<proc | e>` here: the clauses' `proc`, the action's forwarded `e`. So `/_>` is "infer the row, which may mention the signature's other row variables", and the wrapper's contract stays explicit in the parameter. `_` is not a row variable today, so the syntax is free. |
| 37 | + |
| 38 | +Restriction (v1): not on `pub fn` — a published signature spells out its contract. A recursive `/_>` function's self-call performs the body's own row, which is consistent; whether the row is principal is the review point below. |
| 39 | + |
| 40 | +## Consequences |
| 41 | +- The demo's five `<proc, random, io, ffi>` become `<app>`; adding an effect to the domain is one edit. The handler-wrapper tax (pain 2) mostly disappears where the wrapper only forwards a row. |
| 42 | +- The type checker is unchanged in its rows: aliases expand before it, `/_>` uses the existing inference. Both are small, localisable changes (resolution and the signature path), which is the point of keeping them out of the row algebra. |
| 43 | +- The dead-member lint (option A) keeps the expanded rows honest. |
| 44 | + |
| 45 | +## Alternatives considered |
| 46 | +- **Inferring the row when omitted after `-> T`:** silently removes the declared-total check that catches unintended effects. `/_>` gets the convenience without it. |
| 47 | +- **Bundling std effects into one** (`sys` = io+clock+random+ffi): destroys the granularity that is the point of rows; the demo's tests rely on telling `io` from `random`. |
| 48 | +- **Handler-declaration sugar** (a `handler` form deriving the whole wrapper type from the handled effect and its clauses): removes the pattern entirely, but it is a new declaration form with real design surface (clause typing, `ctl`/`final ctl`, return clauses). Deferred until the two smaller ones have been lived with. |
| 49 | +- **Canonical row order in diagnostics and `fmt`:** rows are sets except for scoped duplicates, so sorting is safe only when no label repeats — cheap to check; a formatting nicety, separable from this ADR, and `fmt`'s charter is whitespace-only today. |
| 50 | +- **Per-call-site effect annotations:** more verbosity, not less. |
| 51 | + |
| 52 | +## Open for review |
| 53 | +- Whether `/_>` should stay out of `pub` for good (v1) or the row may be published inferred. |
| 54 | +- The alias's dead-member interaction (a member dead in the alias but live elsewhere), and hover expansion in the LSP. |