title: Using a parsec parser in the IO monad
body: <p>I've defined a parser using Parsec, which has type <code>Parsec Text () a</code> for some <code>a</code>. I've also got a "deal with this chunk" function, which writes the thing I've parsed to a file and has type <code>a -&gt; IO ()</code>. The file format that it's parsing means that we get back to "top level" reasonably frequently.</p>
  
  <p>Is there a way to take my original parser and "lift it" into the IO monad? I'm imagining something with the following type signature:</p>
  
  <pre><code>liftParser :: Parsec Text () a -&gt; (a -&gt; IO ()) -&gt; ParsecT Text () IO ()
  </code></pre>
  
  <p>where the first argument is the pure parser and the second is the "do something with the thing I parsed" function.</p>
  
  <p>Obviously, I can bodge together what I need by redefining my original parser in IO too, but that means my unit tests look horrible, and it just feels like the wrong approach.</p>
  
  <p>Also, I can't do something crazy like calling <code>runParserT</code> because that would drop the source position information - if there's an error on line 1000 of the input, I'd like the error message to say so.</p>
  
  <p>So is there a way to do this and, if so, how? Also, is this a sensible thing to do? I imagine that I'm at least managing to avoid accumulating the output data. And, assuming that I manage something like this, should I expect <code>Parsec</code> to manage to discard the input data that it's already dealt with?</p>