[Haskell-cafe] Tiger compiler in Haskell: annotating abstract syntax tree

Malcolm Wallace malcolm.wallace at me.com
Mon Jul 19 14:59:59 EDT 2010

I would be inclined to add type annotations as an extra constructor of  
the expression representation type.

>  data Exp
>    = IntExp Integer
>    | VarExp Symbol
>    | AssignExp Symbol Exp
>    | IfExp Exp Exp (Maybe Exp)
>    | CallExp Symbol [Exp]
>    | LetExp [Dec] Exp

      | Exp `HasType` Ty

This is particularly useful if the source language allows arbitrary  
type annotations on expressions, because it can cover both the user- 
supplied annotations, and the compiler-inferred ones.  Also, your type  
inference phase is free to add as many or as few annotations into the  
AST as it wishes - they are not required everywhere.


More information about the Haskell-Cafe mailing list