title: Tracking Position when Scanning Tokens complicates Parser
body: <p>I am writing a two pass parser where I first scan the text in to tokens (using <code>Alex</code>) then parse those tokens (using <code>Parsec</code>).  All well and good until I tried to add position information to the tokens so I can write a good error message.</p>
  
  <p>Originally I had:</p>
  
  <pre><code>data Token = TAtom | TString String | TInt Integer | TFloat [...]
  </code></pre>
  
  <p>It seems like I can either add a <code>Position</code> element to each <code>Token</code> constructor or create a new type like <code>data TokenWithPosition = T Token Position</code>.</p>
  
  <p>I have started down the latter path, but now I have a problem of either having to create a <code>TokenWithPosition</code> with a fake position when I want to describe a token in Parsec, or I have to unwrap the <code>TokenWithPosition</code> every time I want to make a comparison.  In short my nice clean grammar is being overrun with code needed to ignore the position information.</p>
  
  <p>So my question: Is there a clean way to track position information without having it complicate the parser in the second pass?  This seems like something that would have a standard solution.</p>