try works in this case, but it won&#39;t if we are using a parser which can consume and then fail (instead of char &#39;a&#39;). In which case we may want it to fail without exploring the second option.<br><br>Hmmm though you might be right. Having lookAhead return Consumed is
only a problem if the parser passed to lookAhead succeeds, but the
parser following lookAhead fails without consuming, which seems like a fairly rare case.<br><br>Although, it would be a problem for cases where the lookAhead is checking for a negation.  For example:<br>parseStuff = (lookAhead parseNotCapital &gt;&gt; identifier) &lt;|&gt; number<br>
wouldn&#39;t work if lookAhead returned Consumed on success, and try doesn&#39;t save us either.<br><br>Even if returning &quot;Consumed&quot; is the desired behavior I&#39;d still say it at least deserves a note in the docs.<br>
<br>Martijn, how did you encounter this problem?<br><br>- Job<br><br><br><div class="gmail_quote">On Thu, Aug 20, 2009 at 2:21 PM, Christian Maeder <span dir="ltr">&lt;<a href="mailto:Christian.Maeder@dfki.de">Christian.Maeder@dfki.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Daniel Fischer wrote:<br>
&gt; Am Donnerstag 20 August 2009 13:44:15 schrieb Martijn van Steenbergen:<br>
&gt;&gt; Goedemiddag café,<br>
&gt;&gt;<br>
&gt;&gt; Consider the following function, using parsec-3.0.0:<br>
&gt;&gt;&gt; la :: Parsec String () (Maybe Char)<br>
&gt;&gt;&gt; la = lookAhead (optionMaybe anyChar)<br>
&gt;&gt; *Lookahead&gt; parseTest (char &#39;a&#39; &lt;|&gt; char &#39;b&#39;) &quot;a&quot;<br>
&gt;&gt; &#39;a&#39;<br>
&gt;&gt; *Lookahead&gt; parseTest (char &#39;a&#39; &lt;|&gt; char &#39;b&#39;) &quot;b&quot;<br>
&gt;&gt; &#39;b&#39;<br>
&gt;&gt; *Lookahead&gt; parseTest (la *&gt; char &#39;a&#39; &lt;|&gt; char &#39;b&#39;) &quot;a&quot;<br>
&gt;&gt; &#39;a&#39;<br>
&gt;&gt; *Lookahead&gt; parseTest (la *&gt; char &#39;a&#39; &lt;|&gt; char &#39;b&#39;) &quot;b&quot;<br>
&gt;&gt; parse error at (line 1, column 2):<br>
&gt;&gt; unexpected &quot;b&quot;<br>
&gt;&gt; expecting &quot;a&quot;<br>
&gt;&gt;<br>
&gt;&gt; The first three work fine and as expected, but the fourth example fails<br>
&gt;&gt; where I would expect success. I know &lt;|&gt; won&#39;t try the rhs if the lhs<br>
&gt;&gt; consumed input, but lookAhead&#39;s documentation promises not to consume<br>
&gt;&gt; any input. Is this a bug in Parsec or am I missing something?<br>
&gt;<br>
&gt; Bad bug in Parsec (from the beginning, the same happens in parsec-2), I&#39;d say.<br>
<br>
</div>I&#39;d say, its a feature. lookAhead returns whatever its argument returns.<br>
 So in this case it returns &quot;Consumed&quot; without consuming.<br>
<br>
You can always wrap around a &quot;try&quot; to force the alternative:<br>
<br>
  parseTest (try (la &gt;&gt; char &#39;a&#39;) &lt;|&gt; char &#39;b&#39;) &quot;b&quot;<br>
<br>
Cheers Christian<br>
<br>
Maybe it should have been:<br>
<div class="im"><br>
  la &gt;&gt; (char &#39;a&#39; &lt;|&gt; char &#39;b&#39;)<br>
<br>
</div>in the first place.<br>
<div><div></div><div class="h5">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>