
Hi Oleg,
From what I understand, you are using a list of integers to encode a path to a subterm. This is a practical and lightweight implementation, but less type-safe: it is easy to encode annotations that do not correspond to any value. Also, it cannot guarantee, with types alone, that every subterm is annotated.
Our solution, on the other way, requires more intrusive changes to the
user's datatype.
Cheers,
Pedro
On Tue, Jul 20, 2010 at 11:06,
Jose' Romildo Malaquias wrote:
I am writing here to ask suggestions on how to annotate an ast with types (or any other information that would be relevant in a compiler phase) in Haskell.
There is also a general way of annotating AST post factum, described in http://okmij.org/ftp/Algorithms.html#tree-annot
The method lets one attach arbitrarily many annotations to an already built AST, *without* the need to change the definition of the datatype. One does not even have to anticipate annotations! The method would work with your AST
data Exp = IntExp Integer | VarExp Symbol | AssignExp Symbol Exp
as _it is_, without any modifications -- neither to the data type definition, nor to the tree.
The method was demonstrated when writing a compiler of sorts: annotating an AST with an inferred type for each node. If the type inference fails, we can still print out the inferred types for the good subexpressions.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe