[Haskell-cafe] All-fail case in asum

Юрий Сыровецкий (Yuriy Syrovetskiy) cblp at cblp.su
Fri Jun 10 16:56:04 UTC 2016


Of course, but I want the *perfect* solution.

I think, this Parser type is not perfectly monoidal, so in general asum and
(<|>) are not interchangeable.
On 10 Jun 2016 19:51, "Erik Hesselink" <hesselink at gmail.com> wrote:

> Disregarding is `asum` should be changed, perhaps you could fix your
> issue by doing:
>
>   myParser = asum [tryA, tryB] <|> fail "input must be either A or B"
>
> Erik
>
> On 10 June 2016 at 16:37, Юрий Сыровецкий (Yuriy Syrovetskiy)
> <cblp at cblp.su> wrote:
> > Hello
> >
> > I want to define some parser such way:
> >
> >     myParser = tryA <|> tryB <|> fail "input must be either A or B"
> >
> > It works. But then I want to rewrite it with asum:
> >
> >     myParser = asum [tryA, tryB, fail "must be A or B"]
> >
> > It works, but the wrong way. Instead of my error it writes "empty".
> > Just "empty".
> >
> > It is so because in base library
> >
> >     asum = foldr (<|>) empty
> >
> > What if it was defined
> >
> >     asum [] = empty
> >     asum [x:xs] = x <|> asum xs
> >
> > It would help me with my parser. But what can this break? Why isn't
> > this done yet?
> >
> > --
> > Yuriy Syrovetskiy, http://cblp.su
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160610/d148a5f9/attachment.html>


More information about the Haskell-Cafe mailing list