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

José Pedro Magalhães jpm at cs.uu.nl
Tue Jul 20 08:43:04 EDT 2010

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

Our solution, on the other way, requires more intrusive changes to the
user's datatype.


On Tue, Jul 20, 2010 at 11:06, <oleg at okmij.org> wrote:

> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100720/fbd77ac6/attachment.html

More information about the Haskell-Cafe mailing list