explanationView source

The formatter#

alpha fmt is the one repository-owned style. There are no style options, because a formatter with options is a formatter with arguments about it. The only flag that changes the output is --expanded, which prints the explicit app spelling of every application instead of bare (f a b).

What it guarantees#

  • parse preserving — the output's significant lexemes are exactly the input's. The formatter verifies this itself and refuses rather than write a file it changed the meaning of.
  • declaration preserving — the output's declaration boundaries are the input's. Same lexemes is not enough: a keyword that moves to the start of a line can re-parse as a new declaration, which is a real defect the fuzzer found and this check now prevents.
  • comment preserving — every comment survives, and a trailing comment stays on its form's line.
  • idempotent — formatting twice changes nothing. Checked over the whole corpus, not asserted.
  • safe on malformed source — a file whose structure is broken is REFUSED, never rewritten, with the reason and the line.

The style#

Declaration headers on one line when they fit; bodies indented two spaces on the next line; a form inline when it fits the width, otherwise one child per line with the closing parenthesis on the last child; binder forms keep their head through . (or = for let); family members one per line; consecutive imports contiguous with one blank line between other declarations.

Width is 100 columns. Indentation stops at column 40: two spaces per nesting level is unbounded, and unbounded indentation makes the OUTPUT quadratic in depth — the corpus's deepest file (702 levels) produced hundreds of megabytes and took two minutes before the cap.

Imports are never sorted. Their order fixes the closure order and therefore the artifact's bytes, so sorting them would change the program.

Commands#

alpha fmt                 # check the closure; exit 1 if any file would change
alpha fmt --write FILES   # rewrite in place
alpha fmt --stdout FILE   # print the formatted file
alpha fmt --verify FILES  # check idempotence and lexeme identity per file
alpha fmt --expanded FILE # the explicit `app` spelling

Evidence#

debug/fmt-check.py drives the formatter over the corpus and records the result in docs/generated/ALPHA-FMT-CHECK.json. The run committed on 2026-09-17 formatted 151 files: every one idempotent and lexeme-identical, none refused, none failed. debug/fmt-depth-bench.py measures the scaling that produced the indentation cap.