Debugging: CLI Tips and Common Errors
Rex is compiled and evaluated in stages:
- Lexing
- Parsing
- Type inference / checking
- Evaluation
Most debugging is about figuring out which stage is failing and adding just enough information to make the problem obvious.
Useful CLI flags
Run a file:
cargo run -p rex -- run path/to/file.rex
Run an inline snippet:
cargo run -p rex -- run -c 'let x = 1 in x + 2'
Show the parsed AST and exit:
cargo run -p rex -- run --emit-ast -c '1 + 2'
Show the inferred type and exit:
cargo run -p rex -- run --emit-type -c 'map ((*) 2) [1, 2, 3]'
“Parse error”: start small
If you hit a parse error:
- Reduce the program to the smallest failing snippet.
- Add parentheses to disambiguate application vs infix operators.
- Prefer layout-style
let/matchwhile debugging.
“Missing typeclass impl”
This usually means you called a type-class method at a type that has no instance.
Typical fixes:
- use a different type (
ListvsArray,OptionvsResult, …), - add an instance (Section 2),
- add a type annotation so the intended instance is selected.
“Ambiguous overload”
This happens when an overloaded value doesn’t have enough information to pick an instance.
Typical fixes:
- add a let-annotation:
let z: i32 = zero in z - add
isascription:(zero) is i32(if you prefer expression ascription style) - use the value in a context that forces a type (e.g.
zero + 1).
The exact defaulting rules are described in Specification.