Counter-intuitively, if you're writing a parser for a programming language, you need it to be a total function. As soon as you build IDE tooling, you need ASTs from invalid or incomplete input.
The parser should return (Ast, List<Error>) rather than Result<Ast, Error>.
miniblog.
Related Posts
What types should you infer when code is invalid?
In Garden, + only applies to integers. What should the type of "x" + "y" be?
(1) Int: This produces cascading errors.
(2) String: We've already emitted an error anyway.
(3) Bottom.
Opinions?
Are there any developer experience advantages for `x := 1` over `let x = 1`?
A `let` keyword probably improves parsing error behaviour, and makes declarations more visible.
:= is more concise though.
I've been using "Expected Int, but got String" for my type error messages, but I've been wondering if I could do better.
"Expected Int here, but this value has type String" or "This expression requires Int, but the value is String".
Do you have a favourite?