<div dir="ltr">Thanks Roman .. I'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"><<a href="mailto:roma@ro-che.info" target="_blank">roma@ro-che.info</a>></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 'a'<br>
<br>
((a >> a) <|> a) >> a<br>
<br>
Suppose that our input is "aa". The result of ((a >> a) <|> a) would be<br>
the list<br>
<br>
[('a', ""), ('a', "a")]<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'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 <<a href="mailto:ckkashyap@gmail.com">ckkashyap@gmail.com</a>> [2013-07-24 08:38:53-0700]<br>
<div class="HOEnZb"><div class="h5">> There is reference in the paper that empty list indicates failure...so<br>
> could we just use it like Maybe? I'd like it very much if I could get<br>
> an example of a missed match by not using the complete match.<br>
><br>
> regards,<br>
> Kashyap<br>
><br>
> Sent from my Windows Phone<br>
> From: Roman Cheplyaka<br>
> Sent: 24/07/2013 8:19 PM<br>
> To: C K Kashyap<br>
> Cc: Haskell Cafe<br>
> Subject: Re: [Haskell-cafe] Parsec question<br>
> Think about this: if you always take only the first element, why do you<br>
> need lists at all?<br>
><br>
> Roman<br>
><br>
> * C K Kashyap <<a href="mailto:ckkashyap@gmail.com">ckkashyap@gmail.com</a>> [2013-07-24 19:56:29+0530]<br>
> > Dear Cafe,<br>
> ><br>
> > I am trying to implement[1] parsec in go using the "Monadic Parser<br>
> > Combinators" paper [2] . I've been able to implement "plus" "bind" and<br>
> > "many"<br>
> > While doing the implementation - I looked at bind closely<br>
> ><br>
> > bind :: Parser a -> (a -> Parser b) -> Parser b<br>
> > p `bind` f = \inp -> concat [f v inp' | (v,inp') <- p inp]<br>
> ><br>
> > I wondered if the result needs the complete list - wouldn't just the first<br>
> > successful value suffice?<br>
> > Perhaps -<br>
> > p `bind` f = \inp -> take 1 $ concat [f v inp' | (v,inp') <- p inp]<br>
> ><br>
> > Will this miss out matches?<br>
> ><br>
> ><br>
> > Regards,<br>
> > Kashyap<br>
> ><br>
> > [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>
> > [2] Monadic Parser Combinators: Graham Hutton, Erik Meijer<br>
><br>
> > _______________________________________________<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></div>