<div dir="ltr">Thanks Roman .. I&#39;ll try and implement laziness to retain the whole list.<div>Regards,</div><div>Kashyap</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 25, 2013 at 3:41 AM, Roman Cheplyaka <span dir="ltr">&lt;<a href="mailto:roma@ro-che.info" target="_blank">roma@ro-che.info</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To construct such an example, you have to ask yourself: when can we get a<br>
list of more than one element?<br>
<br>
Consider this:<br>
<br>
  a = char &#39;a&#39;<br>
<br>
  ((a &gt;&gt; a) &lt;|&gt; a) &gt;&gt; a<br>
<br>
Suppose that our input is &quot;aa&quot;. The result of ((a &gt;&gt; a) &lt;|&gt; a) would be<br>
the list<br>
<br>
  [(&#39;a&#39;, &quot;&quot;), (&#39;a&#39;, &quot;a&quot;)]<br>
<br>
If you proceed with the first element of the list, the overall parse<br>
will fail. It can only succeed if you then try the second element.<br>
<br>
By the way, you shouldn&#39;t confuse Parsec (the library) with the general<br>
concept of parser combinators or the implementation from the paper you<br>
reference. The above parse would fail in Parsec as well, despite the<br>
fact that Parsec allows backtracking.<br>
<br>
Roman<br>
<br>
* Kashyap CK &lt;<a href="mailto:ckkashyap@gmail.com">ckkashyap@gmail.com</a>&gt; [2013-07-24 08:38:53-0700]<br>
<div class="HOEnZb"><div class="h5">&gt; There is reference in the paper that empty list indicates failure...so<br>
&gt; could we just use it like Maybe? I&#39;d like it very much if I could get<br>
&gt; an example of a missed match by not using the complete match.<br>
&gt;<br>
&gt; regards,<br>
&gt; Kashyap<br>
&gt;<br>
&gt; Sent from my Windows Phone<br>
&gt; From: Roman Cheplyaka<br>
&gt; Sent: 24/07/2013 8:19 PM<br>
&gt; To: C K Kashyap<br>
&gt; Cc: Haskell Cafe<br>
&gt; Subject: Re: [Haskell-cafe] Parsec question<br>
&gt; Think about this: if you always take only the first element, why do you<br>
&gt; need lists at all?<br>
&gt;<br>
&gt; Roman<br>
&gt;<br>
&gt; * C K Kashyap &lt;<a href="mailto:ckkashyap@gmail.com">ckkashyap@gmail.com</a>&gt; [2013-07-24 19:56:29+0530]<br>
&gt; &gt; Dear Cafe,<br>
&gt; &gt;<br>
&gt; &gt; I am trying to implement[1] parsec in go using the &quot;Monadic Parser<br>
&gt; &gt; Combinators&quot; paper [2] . I&#39;ve been able to implement &quot;plus&quot; &quot;bind&quot; and<br>
&gt; &gt; &quot;many&quot;<br>
&gt; &gt; While doing the implementation - I looked at bind closely<br>
&gt; &gt;<br>
&gt; &gt; bind :: Parser a -&gt; (a -&gt; Parser b) -&gt; Parser b<br>
&gt; &gt; p `bind` f = \inp -&gt; concat [f v inp&#39; | (v,inp&#39;) &lt;- p inp]<br>
&gt; &gt;<br>
&gt; &gt; I wondered if the result needs the complete list - wouldn&#39;t just the first<br>
&gt; &gt; successful value suffice?<br>
&gt; &gt; Perhaps -<br>
&gt; &gt; p `bind` f = \inp -&gt; take 1 $ concat [f v inp&#39; | (v,inp&#39;) &lt;- p inp]<br>
&gt; &gt;<br>
&gt; &gt; Will this miss out matches?<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Regards,<br>
&gt; &gt; Kashyap<br>
&gt; &gt;<br>
&gt; &gt; [1] <a href="https://github.com/ckkashyap/parsec/blob/master/parsec.go" target="_blank">https://github.com/ckkashyap/parsec/blob/master/parsec.go</a><br>
&gt; &gt; [2] Monadic Parser Combinators: Graham Hutton, Erik Meijer<br>
&gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; Haskell-Cafe mailing list<br>
&gt; &gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; &gt; <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></div>