Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Type Error Provenance<br />
Before our type inference engine would generate somewhat typical type inference error messages. If two<br />
terms couldn’t be unified it simply told us this and some information about the toplevel declaration<br />
where it occurred. Leaving us with a bit of a riddle about this error came to be.<br />
Cannot unify types:<br />
Int<br />
with<br />
Bool<br />
in the definition of ’foo’<br />
Effective error reporting in the presence of type inference is a difficult task, effectively our typechecker<br />
takes our frontend AST and transforms it into a large constraint problem but effectively destroys position<br />
information information in the process. Even if the position information were tracked, the nature of<br />
unification is that a cascade of several unifications can give rise to invalid solution and the immediate<br />
two syntactic constructs that gave rise to a unification fail are not necessarily the two that map back<br />
to human intuition about how the type error arose. Very little research has done on this topic and it<br />
remains a open topic with very immediate and applicable results to programming.<br />
To do simple provenance tracking we will use a technique of track the “flow” of type information through<br />
out typechecker and associate position information associated with the inferred types back to their position<br />
information in the source.<br />
type Name = String<br />
data Expr<br />
= Var Loc Name<br />
| App Loc Expr Expr<br />
| Lam Loc Name Expr<br />
| Lit Loc Int<br />
data Loc = NoLoc | Located Int<br />
deriving (Show, Eq, Ord)<br />
So now inside of our parser we simply attach Parsec information on to each AST node. For example for<br />
the variable term.<br />
variable :: Parser Expr<br />
variable = do<br />
x