Feature contract: pipe#
1. Lexical and grammar rules, including precedence and termination#
(pipe X L1 L2 ... Ln), n >= 1. X is one term. Each link is one identifier
(a function, a qualified name, or a form head such as succ) or a
parenthesised prefix (F a ...) that an identifier begins. The form means
(Ln ... (L2 (L1 X))) with the term so far as each link's FIRST operand:
the term goes right after the link's identifier, so (pipe x (f a) g (h b c))
is (h (g (f x a)) b c). It is the mirror of then, whose links take the
rest of the chain as their LAST operand: a chain that nests through the first
operand, such as a record built one field at a time
((set (set (set empty 4 a) 8 b) 12 c)), is written flat. Fewer than two
operands, an empty link, or a link that is neither a name nor a prefix an
identifier begins is ALPHA-PARSE-PIPE. pipe is a reserved head in every
edition, as nest and then are: a function or binder of that name is
applied as (app pipe x). No workspace definition applies 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 X must have the type the first link's first operand needs
(ALPHA-TYPE-MISMATCH otherwise), and quantities are counted over the
written-out chain.
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,
parsePipe), 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-PIPE for a malformed chain. Each rebuilt link spans the whole
pipe form, so a diagnostic inside the chain points at the form and an
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 pipe and its first term on the first line when they
fit, and otherwise lays a pipe out as any form. The registered migration
pipe-left-chains rewrites a maximal chain of three or more steps through
the first operand, of any heads, into one pipe: a step is a form whose head
is an identifier that is no binder, branch or other special form, and the
chain runs down first operands to the first one that is not such a form (X).
A step with no operand besides the first becomes a bare link. Two steps stay
nested, because the pipe would save nothing, and so does a chain whose steps
all take one operand ((f (g (h x)))), which nests through its last operand
as well and is then's or nest's to write. X and every operand keep their
text; a chain written on one line stays on one line, and one over several
lines puts each link on its own line. A chain inside another's X or operands
is written in the same pass. A comment between the parts that move leaves the
chain as it is. alpha migrate proves the rewritten module has the same
core.
9. Positive, negative, execution, and edge-case tests#
tests/language/draft/pipe/: name and prefix links, mixed heads, one link, a
record built field by field, a pipe as a then's last term and as another
pipe's first term, refl against each written-out chain, a native run
(exit 22), and the operand-count, empty-link, literal-link and first-term-type
refusals. debug/lang-contract-check.py checks the edition gate both ways
with tests/language/PipeUnderAlpha2026.alpha;
scripts/proofs/alpha-dependent-telescope-parser.sh checks the self-hosted
front end against the written-out chains; debug/migrate-check.py checks the
migration.
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#
- The self-hosted front end (
packages/compiler) expandspipeunder alpha-2027 with the limits of itsthen: a literal link is not refused there, and(pipe x ())fails as an empty form. - As a
thenlink, apipeis a prefix like any other:(then (pipe x f) g)is(pipe x f g), so the rest of the chain becomes its last link.