prompts: fix the reference's own record/variant construction syntax - #153
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Shapeexample was invalid Lex:lex checkon 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 }), constructedRect({ w: 1.0, h: 2.0 }), matchedRect({ 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.lex-economyrepo'sidentitymodule build (dogfoodingimpl_test_fix_loop_verifiedon a brand-new domain) stalled for close to an hour on a closely related mistake — writingKeyPair { 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 confusingunknown_variantorexpected RParenerror that doesn't say what's actually wrong.Shapeexample, added a workedCompany/incorporateexample showing bare-literal construction, and added two new pitfalls-table rows ({ field = value }vs:; theTypeName-prefixed construction mistake, both for plain records and for record-shaped ADT variants).Test plan
lex check/lex fmt --check/lex doc-sync --check— cleanlex test tests— 4/4 existing tests still passpitfalls_topic()andreference()'s actual string output to confirm escaping and content are correct, not just that the outer.lexfile parses/tmpscratch repro) before being added here🤖 Generated with Claude Code