[Haskell-cafe] All-fail case in asum

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


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


More information about the Haskell-Cafe mailing list