-
Notifications
You must be signed in to change notification settings - Fork 0
let x = EXPR in BODY: membership in in value position requires parentheses #71
Open
Description
Summary
In let x = EXPR in BODY, the value expression is parsed with parse_expr_no_in() so the parser can distinguish the in keyword (separating value from body) from the in binary membership operator. This means membership tests in the value position require parentheses.
Example
// FAILS - parser treats first `in` as let...in keyword separator:
let present = k in s in present or not(present)
// WORKS - parentheses disambiguate:
let present = (k in s) in present or not(present)
Context
This is the remaining case where in is genuinely ambiguous. In quantifier/fix bodies (after :), in is unambiguously a binary operator and was fixed in 7ec1af7. But in let...in value position, both interpretations are syntactically valid.
Possible approaches
- Status quo — require parentheses (documented behavior, simple)
- Greedy parsing — parse the value with
parse_expr()and use heuristics to find thelet...inkeyword boundary (fragile, complex) - Alternative syntax — use a different keyword for
letbody separation, e.g.let x = EXPR then BODYorlet x = EXPR { BODY }(breaking change)
Option 1 is probably fine — it's a minor inconvenience and the error message could be improved to suggest parentheses.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
No labels