title: Reassociating trees in Template Haskell AST's
body: <p>I'm upgrading a library where I translate Haskell to another language. Right now I'm using <a href="http://hackage.haskell.org/package/haskell-src-meta-0.0.3.1/docs/Language-Haskell-Meta-Parse.html" rel="nofollow">Meta.Parse</a> to read in a Haskell module, and get back its TemplateHaskell AST, as described <a href="http://hackage.haskell.org/package/template-haskell-2.8.0.0/docs/Language-Haskell-TH-Syntax.html" rel="nofollow">here</a>.</p>
  
  <p>The problem I'm running into is that, when I run the parse, I get a bunch of infix operators parsed as UInfixE and UInfixP, meaning that they are of unresolved associativity. </p>
  
  <p>The <a href="http://hackage.haskell.org/package/template-haskell-2.8.0.0/docs/Language-Haskell-TH-Syntax.html#infix" rel="nofollow">description of the associativity</a> talks about how the Haskell compiler resolves these.</p>
  
  <p>I'm wondering, is there a function avaliable which can do this reassociation on the trees I get from parsing? I'm looking for something like this:</p>
  
  <pre><code>reassoc :: [Dec] -&gt; [Dec]
  </code></pre>
  
  <p>I could write the massive AST traversal that does this, but it seems like it would be a massive amount of boilerplate, and clearly the function already exists in some form (hopefully in a form that plays nice with TH).</p>
  
  <p>Does such a thing exist? Is there an easy way to get rid of unresolved infix operators in the AST I get from parsing declarations?</p>
  
  <p>EDIT: Even a function which, given the Name of an operator, could give its precedence and associativity, would be very useful.</p>