[Haskell-cafe] MonadPlus and Alternative folds
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sat Sep 19 17:13:18 UTC 2015
On Sat, Sep 19, 2015 at 01:25:00AM -0400, David Feuer wrote:
> It kind of seems like there should be fold-like things to match some and
> foldrAlt :: Alternative f => (a -> b -> b) -> b -> f a -> f b
> foldrAlt c n m = foldr1Alt c n m <|> pure n
> foldr1Alt :: Alternative f => (a -> b -> b) -> b -> f a -> f b
> foldr1Alt c n m = c <$> m <*> foldrAlt c n m
An Alternative allows list-like behaviour when it comes to *construction*,
but offers no operation analogous to pattern-matching and therefore doesn't
allow you to look inside it or do any sort of *destruction*.
I tried foldrAlt and it looped forever, as I expected. I also expect the
others to loop forever.
More information about the Haskell-Cafe