<p dir="ltr">Of course, but I want the *perfect* solution.</p>
<p dir="ltr">I think, this Parser type is not perfectly monoidal, so in general asum and (<|>) are not interchangeable.</p>
<div class="gmail_quote">On 10 Jun 2016 19:51, "Erik Hesselink" <<a href="mailto:hesselink@gmail.com">hesselink@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Disregarding is `asum` should be changed, perhaps you could fix your<br>
issue by doing:<br>
<br>
myParser = asum [tryA, tryB] <|> fail "input must be either A or B"<br>
<br>
Erik<br>
<br>
On 10 June 2016 at 16:37, Юрий Сыровецкий (Yuriy Syrovetskiy)<br>
<<a href="mailto:cblp@cblp.su">cblp@cblp.su</a>> wrote:<br>
> Hello<br>
><br>
> I want to define some parser such way:<br>
><br>
> myParser = tryA <|> tryB <|> fail "input must be either A or B"<br>
><br>
> It works. But then I want to rewrite it with asum:<br>
><br>
> myParser = asum [tryA, tryB, fail "must be A or B"]<br>
><br>
> It works, but the wrong way. Instead of my error it writes "empty".<br>
> Just "empty".<br>
><br>
> It is so because in base library<br>
><br>
> asum = foldr (<|>) empty<br>
><br>
> What if it was defined<br>
><br>
> asum [] = empty<br>
> asum [x:xs] = x <|> asum xs<br>
><br>
> It would help me with my parser. But what can this break? Why isn't<br>
> this done yet?<br>
><br>
> --<br>
> Yuriy Syrovetskiy, <a href="http://cblp.su" rel="noreferrer" target="_blank">http://cblp.su</a><br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div>