alpha-2027 · draft-alpha-2027 · tests/language/draft/open-bodyView source

Feature contract: open bodies#

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

A BODY is what follows the . of a lambda, pi or sigma binder (each binder of a telescope included), of an eliminator branch or a match case, or of a prophecy's (RESOLVED . RESULT), and what follows the in of a let or let*. The body runs to the ) that closes its form.

A body is one term. Under alpha-2027 it may also be OPEN: when its first token is a name and more tokens follow before that ), the body is the form those tokens spell, parenthesised:

(lambda q x : A . f a b)          means  (lambda q x : A . (f a b))
(branch C x . constructor F K x)  means  (branch C x . (constructor F K x))
(let q x : A = v in nat-add x x)  means  (let q x : A = v in (nat-add x x))

The first token may be any identifier, including a form head (eliminate, constructor, nest, lambda, ...), so an open body may itself hold an open body: (lambda q x : A . lambda r y : B . f x y) is (lambda q x : A . (lambda r y : B . (f x y))).

Termination and precedence: a body written as one term ends at that term, so every body that parsed before this feature parses as it did. Type N is one term, and a telescope's QUANTITY NAME : after a . is read as the next binder before a body is. A body that a parenthesised group or a literal begins cannot run on: (lambda q x : A . (f a) b) is ALPHA-PARSE-UNEXPECTED (expected )). There is no new reserved word.

2. Scope and binding rules, including generated names#

None of its own: the open body is the parenthesised form written out, so names resolve in it as they would there. No names are generated.

3. Type and quantity requirements#

The parenthesised form's: it is checked against the binder's codomain, the branch's motive or the let's expected type exactly as ( ... ) would be (ALPHA-TYPE-MISMATCH otherwise), and quantities are counted over it.

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

Those of the parenthesised form.

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

The parser rebuilds the body's tokens with the parentheses and parses them (Alpha/Surface/Parser.hs, parseBody, used by the binder, branch, match case, let, let* and prophecy parsers), so elaboration sees the parenthesised form and the core is byte-identical to it.

6. Representation and target support, where relevant#

Unchanged.

7. Error codes and primary/secondary origins#

No code of its own. The rebuilt form spans from the body's first token to the enclosing ), so a diagnostic inside it points at the body and each operand keeps its own span. Under an edition other than alpha-2027 the spelling is ALPHA-EDITION-UNSUPPORTED-FORM at the body's first token, found on the lexemes (Module.draftSyntaxSpans): a . or in followed by a name and then anything but ) (or, after Type, a level).

8. Formatting and migration rules#

The formatter (Alpha/Surface/Format.hs, formatFormWith) lays an open body out as the parenthesised form would be, without the parentheses: inline when it fits, otherwise its head rule applies (a nest keeps its head on the first line, a binder its binders) with its children indented under it, and the enclosing form's ) attaches to its last line.

The registered migration open-body removes the parentheses of a body that is a parenthesised form a name begins, written last in a lambda, pi, sigma, branch, case, let or let* (the enclosing form's head decides which . or in begins a body, so an identifier spelled in elsewhere is never read as the keyword). alpha migrate proves the rewritten module has the same core. debug/fewer-parentheses-migrate.py runs it last, after the chain rewrites, over the self-hosted compiler's source closure too (ALPHA_MIGRATE_CLOSURE), since that front end reads open bodies (see below).

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

tests/language/draft/open-body/: an open lambda body, an eliminator as an open lambda body with open branch bodies, an open let body, a one-term body and a Type 0 body (unchanged), refl against each parenthesised spelling, a native run (exit 42), and the run-on-after-a-group and wrong-type refusals. debug/lang-contract-check.py checks the edition gate both ways with tests/language/OpenBodyUnderAlpha2026.alpha.

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

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

Known discrepancies and limits#

  • The self-hosted front end (packages/compiler/src/Compiler/Parser.alpha) reads open bodies on its syntax tree: syntaxExpandOpenBody, run children-first with nest and then (syntaxExpandNest), wraps the items after the body's . (a telescope's QUANTITY NAME : skipped) or in of a lambda, pi, branch, case, let or let*, and after the . of a prophecy's (RESOLVED . RESULT) (syntaxOpenResolvedGroup), into one node and expands that node in turn; syntaxUsesOpenBody gates it to alpha-2027 with the other fewer-parentheses spellings. It differs from the bootstrap in three ways: it has no sigma form at all (so no sigma body to open); a body holding top-level punctuation (., :, =, <-) that its head does not read stays shut and is refused as trailing items (the bootstrap opens it and refuses the punctuation); and under alpha-2026 such a body is refused as trailing items, not as an edition error. scripts/proofs/alpha-dependent-telescope-parser.sh checks each open body against its parenthesised twin.
  • Bare nullary names are still not read by the self-hosted front end, so the migration leaves bare-nullary-name out for its source closure.
  • Only a body that ends its form opens: an eliminator's motive, a let's value and a binder's domain are not bodies and keep their parentheses.