[Haskell-cafe] All-fail case in asum

Erik Hesselink hesselink at gmail.com
Fri Jun 10 16:51:13 UTC 2016


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


More information about the Haskell-Cafe mailing list