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

Reply via email to