Skip to content

prompts: fix the reference's own record/variant construction syntax - #153

Merged
alpibrupa merged 1 commit into
mainfrom
fix/record-construction-syntax-docs
Sep 8, 2026
Merged

prompts: fix the reference's own record/variant construction syntax#153
alpibrupa merged 1 commit into
mainfrom
fix/record-construction-syntax-docs

Conversation

@alpibrupa

Copy link
Copy Markdown
Contributor

Summary

  • The canonical quick-start's own Shape example was invalid Lex:
    type Shape = Circle(Float) | Rect { w :: Float, h :: Float }
    match shape { Circle(r) => ..., Rect { w, h } => w * h }
    lex check on that exact snippet: parse error ... expected \import`, `type`, or `fn` at top level, got Some(LBrace). A record-shaped variant's payload needs parens like any other variant argument — Rect({ w :: Float, h :: Float }), constructed Rect({ w: 1.0, h: 2.0 }), matched Rect({ w, h }) => ...— there is no bareRect { ... }form. Everylex-code` invocation this session opened with this example as the FIRST thing shown for algebraic data types.
  • Found live: a fresh lex-economy repo's identity module build (dogfooding impl_test_fix_loop_verified on a brand-new domain) stalled for close to an hour on a closely related mistake — writing KeyPair { secret: x, public: y } for a plain record type alias (not a sum type), which also doesn't parse. Records construct with a bare literal, { field: value, ... } — the type name is never written at construction, only in an annotation or return type; TypeName { ... } reads as an ADT variant lookup and fails with a confusing unknown_variant or expected RParen error that doesn't say what's actually wrong.
  • Confirmed all of this with minimal repros against the real compiler before touching anything, including that the fixed forms type-check and the broken forms don't.
  • Fixed the quick-start's Shape example, added a worked Company/incorporate example showing bare-literal construction, and added two new pitfalls-table rows ({ field = value } vs :; the TypeName-prefixed construction mistake, both for plain records and for record-shaped ADT variants).

Test plan

  • lex check / lex fmt --check / lex doc-sync --check — clean
  • lex test tests — 4/4 existing tests still pass
  • Rendered pitfalls_topic() and reference()'s actual string output to confirm escaping and content are correct, not just that the outer .lex file parses
  • Every new/changed example snippet verified against the real compiler in isolation (/tmp scratch repro) before being added here

🤖 Generated with Claude Code

The canonical quick-start's own Shape example was invalid Lex:

  type Shape = Circle(Float) | Rect { w :: Float, h :: Float }
  match shape { Circle(r) => ..., Rect { w, h } => w * h }

`lex check` on that exact snippet: "parse error ... expected `import`,
`type`, or `fn` at top level, got Some(LBrace)". A record-shaped
variant's payload needs parens like any other variant argument --
Rect({ w :: Float, h :: Float }), constructed Rect({ w: 1.0, h: 2.0 }),
matched Rect({ w, h }) => ... -- there is no bare `Rect { ... }` form.
Every lex-code invocation this whole session opened with this example
as the FIRST thing shown for algebraic data types.

Found live: a fresh lex-economy repo's identity module build (a
different, new-domain dogfood of impl_test_fix_loop_verified) stalled
for close to an hour on a closely related mistake -- writing
`KeyPair { secret: x, public: y }` for a plain record TYPE ALIAS (not
a sum type), which also doesn't parse. Records construct with a BARE
literal, `{ field: value, ... }` -- the type name is never written at
construction, only in an annotation or return type; `TypeName { ... }`
reads as an ADT variant lookup and fails with a confusing
"unknown_variant" or "expected RParen" error that doesn't say what's
actually wrong. Confirmed all of this with minimal repros against the
real compiler before touching anything, including that the fixed forms
type-check and the broken forms don't.

Fixed the quick-start's Shape example, added a worked Company/
incorporate example showing bare-literal construction, and added two
new pitfalls-table rows (`{ field = value }` vs `:`; the TypeName-
prefixed construction mistake, both for plain records and for
record-shaped ADT variants).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@alpibrupa
alpibrupa merged commit c351853 into main Sep 8, 2026
1 check passed
@alpibrupa
alpibrupa deleted the fix/record-construction-syntax-docs branch September 8, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant