title: How should I represent an AST annotated with additional information?
body: <p>Let's say I have a simple data type representing an AST in some language:</p>
  
  <pre><code>data Term = Var String
            | Num Integer
            | Expr [Term]
  </code></pre>
  
  <p>(In reality it would obviously have more constructors than this.)</p>
  
  <p>I can use this to write a simple evaluation function which matches against the AST structure:</p>
  
  <pre><code>eval :: Term -&gt; Result
  eval (Var name)   = lookup name
  eval (Num n)      = return n
  eval (Expr exprs) = ...
  </code></pre>
  
  <p>Can I annotate the AST with information like line numbers without changing how the pattern matching works? </p>
  
  <p>(If I didn't mind changing the patterns, I could use record syntax or view patterns, of course.)</p>