waxwing

Effect operation namespaces: design (FX020)

Status: approved and implemented on branch fx020 (2026-10-13 to 2026-10-14); not merged. The user approved this design in conversation on 2026-10-13, together with review refinements. As built: docs/adr/012- effect-namespaces.md (one wording, the multi-candidate hint, awaits the user’s approval). Sequencing: after Text v1, because both rework the parser, and before Records (R001), because r.field must coexist with Effect.op.

Problem

Operation names currently share one global namespace with functions, and collisions resolve silently and wrongly. Both cases below were reproduced on main on 2026-10-13:

Declaration uniqueness across effects is rejected by the user: independent services must be able to reuse natural names such as get, log and query.

User decisions (2026-10-13)

  1. Always qualified. Every effect operation is called as Effect.op. A bare operation name is never in scope by default. Rationale: adding an effect elsewhere can never break existing code, because there is no ambiguity rule to trip.
  2. Aliases at the dependency declaration. A signature may alias an effect and import selected operations bare, using braces: with Database as D + Log { log, info as note }.
  3. Built-ins follow the same rule. It is Console.print and Fail.fail, and with Console { print } gives the short form. Built-ins get no special syntax or naming rules anywhere. Like PureScript/Haskell, built-ins should be ordinary declarations wherever possible.
  4. Scoping is lexical, and explicit wins.
    • Imports act like bindings at the top of the body, and shadow global functions.
    • Parameters and let shadow imports. Lambdas inherit them.
  5. Review refinements, all accepted:
    • an alias leaves the canonical name valid;
    • qualified lookup does not depend on the row;
    • a parameterized import binds its arguments;
    • duplicates compare resulting names;
    • shadowing has no type-directed fallback;
    • hints never choose a binding.

1. Surface

Qualified operation call. Effect.op(args), for example Database.query(id), Console.print(x) or Fail.fail(NotFound(3)).

Operation references. A qualified operation is also a value. For example, Database.query can be passed as an argument without being called, as in map(Database.query, ids), exactly as a bare operation reference (the compiler’s existing OperationRef) works today. An imported bare name is a reference in the same way: with Fail(Error) { fail }, fail may be passed as a value of the family’s operation type.

Signature aliases and imports. These are allowed only in a function declaration’s own row: the with of its final stage. They are scoped to that function’s body. Alias or import syntax in any other written row is an error (§3). Other written rows include:

The rule is that one row, one body, one scope. A function’s bindings are therefore all visible in its signature line. The forms, in order:

[nofail | nofail(k)] Effect[(args)] [as Alias] [{ op [as name], … }]

Handlers are unchanged. In handler Log { log(n) => … } and handle e { fail(error: E) => … }, clause heads name the handled effect’s own operations. Clause bodies follow the ordinary rules, so a body that performs Log writes Log.log or uses an import of the enclosing function.

2. Resolution rules

3. Static rules (errors)

The texts below are approved by the user. The two that were marked pending were approved on 2026-10-13. The duplicate-binding errors are E_SYNTAX at the offending name, each with a note at the first binding.

Unbound bare operation names. These keep the existing unbound-name error and code, with a hint attached in the existing hint form: ; use Log.log, or import it with Log { log }.

4. Built-ins and the prelude

5. Interaction with other work

6. Migration

Every existing program uses bare operation names: examples, hundreds of test programs, the reference interpreter’s corpus and the generator.

7. Acceptance and evidence

Plan-time amendments (2026-10-13)

A survey of the compiler while writing the plan found four facts the design did not state. Each one is recorded here, and none adds user-facing text.

  1. fail is a keyword today. The parser recognises fail(e) as its own expression form (Syntax.Fail) before ordinary names. Under this design, fail stops being syntax: Fail.fail(e), or an imported fail, is an ordinary operation call whose family comes from e. The handle clause head fail(error: E) => is a clause head naming the handled effect’s operation, and it stays. This removes a special form, in line with the principle that built-ins get no special syntax.
  2. Console and Fail are not declared effects. They are names hard-coded in row resolution, with no declaration and no operation table. FX020 gives them a built-in declaration table, resolved like user effects, so that Console.print, Fail.fail, imports and the collision rule (§4) work uniformly.
    • print accepts any printable type, so it cannot be written as an ordinary Waxwing declaration until type classes exist (C001).
    • Like show, it stays compiler-provided. This is a recorded temporary gap, not a design choice.
  3. Migration is large. About 818 call sites exist across 170 test files, plus 118 .wxw fixtures, and many tests pin exact columns that a qualifier shifts. The migration therefore runs in reviewable stages:
    1. qualified names and imports are added while bare operation names still resolve;
    2. the corpus is migrated in chunks;
    3. bare operation resolution and the fail keyword are removed, together with the unbound-name hint.

    Verify passes after every stage.

  4. Pinned spans. When a migrated test pins a span that the qualifier shifts, the new span is the old one moved by exactly the inserted characters. Each such update is mechanical and is checked in review. The rewrite tool locates operation names from the compiler’s own resolved output, never from a regular expression, so a local that shadows an operation name is never rewritten.