[Haskell-cafe] MonadPlus and Alternative folds
Olaf Klinke
olf at aatal-apotheke.de
Sat Sep 19 17:27:11 UTC 2015
Is there an instance of Alternative where some and many are not bottom? The usual example monads, [] and Maybe, don't serve as a source of intuition.
In general I agree with David: If f is a functor such that every type (f a) is a monoid, then there should be folds. The usual question here is: Your functions have types more general than the known foldr and foldl. Do your functions specialize to the known ones? It seems not.
For example, foldrAlt (+) 0 [1,2,3] diverges, and so does foldlMP' (+) 0 [1,2,3].
I have doubts that knowing how to append two lists gives you access to the recursive structure of a list. Note that mplus is a _constructor_ of lists, while recursion is built on _destructors_. The same seems to apply to all other functions provided by Applicative, Alternative and MonadPlus. The foldr of Data.Foldable, by contrast, accepts a foldable structure and produces something which is not a foldable structure. Hence it must have access to the internals of that foldable structure.
Olaf
More information about the Haskell-Cafe
mailing list