alpha-2027 · draft-alpha-2027 · tests/language/draft/nestView source

Feature contract: nest#

1. Lexical and grammar rules, including precedence and termination#

(nest HEAD X1 X2 ... Xn Z), n >= 1. HEAD is one identifier (a function, a qualified name, or a binary form head such as bytes-cons) or a parenthesised prefix (P1 ... Pk) whose tokens begin every link, such as (constructor F C) or (f a). Each operand is one term. The form means (HEAD X1 (HEAD X2 ... (HEAD Xn Z))), with a parenthesised HEAD spliced without its parentheses. Fewer than two operands, or an empty parenthesised head, is ALPHA-PARSE-NEST. nest is a reserved head in every edition, as resolve and hole are: a function or binder of that name is applied as (app nest x), because (nest ...) always parses as this form (under alpha-2026 it is then refused by the edition gate). No workspace definition used the name.

2. Scope and binding rules, including generated names#

None of its own: each link is the term written out, so names resolve in each link as they would in the chain. No names are generated.

3. Type and quantity requirements#

The chain's: every link is checked as the explicit application or form it stands for, so the last operand must have the type the innermost link's last argument needs (ALPHA-TYPE-MISMATCH otherwise), and quantities are counted over the written-out chain (a variable in the HEAD prefix is used once per link).

4. Effects, totality, and evaluation-order rules#

Those of the chain it abbreviates.

5. Elaboration into existing core or a specifically versioned new core extension#

The parser rebuilds the chain's tokens and parses them (Alpha/Surface/Parser.hs, parseNest), so elaboration sees the explicit chain and the core is byte-identical to it.

6. Representation and target support, where relevant#

Unchanged.

7. Error codes and primary/secondary origins#

ALPHA-PARSE-NEST for a malformed nest. Each rebuilt link spans the whole nest form, so a diagnostic inside the chain points at the form and the offending operand keeps its own span. Under an edition other than alpha-2027 the spelling is ALPHA-EDITION-UNSUPPORTED-FORM, found on the lexemes (Module.draftSyntaxSpans).

8. Formatting and migration rules#

The formatter keeps nest and its head on the first line, and otherwise lays a nest out as any form. The registered migration nest-right-chains rewrites a maximal right-nested chain whose links share one head prefix, spelled identically, with the same number of operands, into one nest, when that saves parentheses (two links for a one-identifier head, three for a parenthesised one). Heads with binders or branches (lambda, let, match, eliminate, ...) are never chained. A comment inside a removed prefix ends the chain before that link. alpha migrate proves the rewritten module has the same core.

9. Positive, negative, execution, and edge-case tests#

tests/language/draft/nest/: a binary-form head, a constructor prefix, a function prefix with a fixed first argument, a nest inside a nest operand, refl against each written-out chain, a native run (exit 42), and the operand-count, empty-head and chain-type refusals. debug/lang-contract-check.py checks the edition gate both ways with tests/language/NestUnderAlpha2026.alpha.

10. Compatibility with the old edition, serialized forms, and cache keys#

alpha-2026 refuses the spelling; written-out chains stay valid in both editions. No core, interface or artifact schema changes.

Known discrepancies and limits#

  • A link takes exactly one operand besides the prefix and the rest of the chain; a constructor with two fields before its recursive field (a map entry with key and value) is chained only by putting the key in the prefix when it is the same for every link.
  • The self-hosted front end (packages/compiler) expands nest under alpha-2027 (scripts/proofs/alpha-dependent-telescope-parser.sh), with two differences: Type N is two operands to it, not one, and (nest () a b) fails as an empty form before nest is reached. Both are still refusals or unused spellings; its own closure is written with nest.