
If you aren’t scared of the dependencies: semigroupoids has asum1 (yet it’s easy to write yourself) https://s3.amazonaws.com/haddock.stackage.org/lts-6.2/semigroupoids-5.0.1/Da... λ Prelude Data.Semigroup.Foldable Data.List.NonEmpty > asum1 ([Right 1, Right 2, Left "error"] :: NonEmpty (Either String Int)) Right 1 λ Prelude Data.Semigroup.Foldable Data.List.NonEmpty > asum1 ([Left "error"] :: NonEmpty (Either String Int)) Left "error" - Oleg
On 10 Jun 2016, at 17:37, Юрий Сыровецкий (Yuriy Syrovetskiy)
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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe