Don't worry, your Parser is a functor
For those of us who don’t stare at parsers on a regular basis, this seems odd to me:<p><pre><code>    newtype Parser a = P (String -&gt; Maybe (String, a))
</code></pre>
So, on a successful parse, it returns the result and the rest of the string. That’s seems error prone and rather weak. What ensures that the “rest of the string” is, in fact, a suffix of the input?  I assume the purpose of this design is for compatibility with lazy input sequences, where the “rest of the string” could still be lazy. But surely some Haskell type magic could ensure that the supposed lazy suffix is actually a suffix.<p>If I were writing a serious parser intended for human use with nice error messages, I would want to know the <i>position and length</i> of the parsed output, which I could infer from actual strings with known length, but which I may not be able to efficiently infer from lazy sequences.<p>So I’m confused. Why is this a good design?