[Haskell-cafe] All-fail case in asum

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Jun 10 15:39:27 UTC 2016


I think we're getting a little off track.  The point is that the behaviour
Yuriy is seeing is inconsistent.

Yuriy, can you please post some complete code demonstrating your problem?  I
have not been able to replicate it.

Tom

On Fri, Jun 10, 2016 at 11:32:45AM -0400, David Feuer wrote:
> Or, to keep it a fold,
> 
> asum xs = foldr go (fromMaybe empty) xs Nothing where
>   go x r Nothing = r (Just x)
>   go x r (Just prev) = prev <|> r (Just x)
> On Jun 10, 2016 11:09 AM, "Dan Burton" <danburton.email at gmail.com> wrote:
> 
> Add a pattern match for the single-element list to stop it from hitting the
> empty list base case.
> 
> asum [] = empty
> asum [x] = x
> asum (x:xs) = x <|> asum xs


More information about the Haskell-Cafe mailing list