<div class="gmail_extra">Hi Romildo,<br><br>If I understand correctly, you now want to add annotations to mutually-recursive datatypes. The annotations package supports that. Section 8 of our paper [1] gives an example of how to do that, and also Chapter 6 of Martijn&#39;s MSc thesis [2].<br>

<br>Let me know if these references do not answer your question.<br><br><br>Cheers,<br>Pedro<br><br>[1] <a href="http://www.dreixel.net/research/pdf/gss.pdf">http://www.dreixel.net/research/pdf/gss.pdf</a><br>[2] <a href="http://martijn.van.steenbergen.nl/projects/Selections.pdf">http://martijn.van.steenbergen.nl/projects/Selections.pdf</a><br>

<br><div class="gmail_quote">On Thu, Apr 26, 2012 at 10:07,  <span dir="ltr">&lt;<a href="mailto:j.romildo@gmail.com" target="_blank">j.romildo@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hello.<br>
<br>
I need to annotate abstract syntax tree with additional information in a<br>
compiler.<br>
<br>
Using the Annotations package[1] I have written the following small<br>
program:<br>
<br>
  import Annotations.F.Annotated<br>
  import Annotations.F.Fixpoints<br>
<br>
  data ExprF r<br>
    = Num Double<br>
    | Var String<br>
    | Add r r<br>
    | Sub r r<br>
    | Mul r r<br>
    | Div r r<br>
    deriving (Eq,Show)<br>
<br>
  type BareExpr = Fix ExprF<br>
<br>
  e :: BareExpr<br>
  e = In (Mul (In (Num 5))<br>
              (In (Add (In (Var &quot;x&quot;))<br>
                       (In (Num 8)))))<br>
<br>
<br>
  type ValExpr = Fix (Ann Double ExprF)<br>
<br>
  type Memory = [(String,Double)]<br>
<br>
  eval :: Memory -&gt; BareExpr -&gt; ValExpr<br>
  eval _ (In (Num x))   = In (Ann x (Num x))<br>
  eval m (In (Var x))   = let y = case lookup x m of<br>
                                    Just k -&gt; k<br>
                                    Nothing -&gt; 0<br>
                          in In (Ann y (Var x))<br>
  eval m (In (Add x y)) = op m (+) Add x y<br>
  eval m (In (Sub x y)) = op m (-) Sub x y<br>
  eval m (In (Mul x y)) = op m (*) Mul x y<br>
  eval m (In (Div x y)) = op m (/) Div x y<br>
<br>
  op m f k x y = let x&#39;@(In (Ann v1 _)) = eval m x<br>
                     y&#39;@(In (Ann v2 _)) = eval m y<br>
                 in In (Ann (f v1 v2) (k x&#39; y&#39;))<br>
<br>
<br>
With these definitions we can represent simple arithmetic expressions<br>
and we can also evaluate them, annotating each node in the abstract<br>
syntax tree with its corresponding value.<br>
<br>
Now I want to add statements to this toy language. One statement may be<br>
a print statement containing an expression whose value is to be printed,<br>
an assign statement containing an identifier and an expression, or a<br>
compound statement containing two statements to be executed in sequence.<br>
<br>
How the data types for statements can be defined?<br>
<br>
How a function to execute an statement anotating its node with the<br>
corresponding state (memory plus output) after its execution can be<br>
defined?<br>
<br>
Without annotations the type of statements could be:<br>
<br>
  data Stm<br>
    = PrintStm Expr<br>
    | AssignStm String Expr<br>
    | CompoundStm Stm Stm<br>
<br>
How to enable annotations in this case? Note that Stm uses both Expr and Stm.<br>
<br>
<br>
[1]  <a href="http://hackage.haskell.org/package/Annotations" target="_blank">http://hackage.haskell.org/package/Annotations</a><br>
<br>
<br>
Romildo<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>