Open timsueberkrueb opened 2 weeks ago
Here is one idea I had about how to solve this: First, observe that substitution only changes variables. So we could change the AST node for variables to add an extra field:
struct Variable {
...,
/// Elaborated due to dependent. pattern matching.
elaborated: Option<Exp>
}
And then we define an operation elaborate
which is just like substitution, but fills in this elaboration instead of replacing the variable. We could also avoid code duplication by reusing the substitution code appropriately.
Consider the following example:
Our dependent pattern matching substitutes the unification not only on the rhs's expected type but also on the rhs expression. This means that the AST changes during typechecking. Therefore, it makes a difference whether we pretty-print the checked vs. the unchecked output:
cargo run -- fmt examples/foo.pol
cargo run -- fmt --checked examples/foo.pol