Re: [Haskell-cafe] MonadPlus and Alternative folds

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

Am 19.09.2015 um 19:27 schrieb Olaf Klinke
: 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.
Parser from optparse-applicative doesn’t give bottom for them. They don’t use the default definition, though. (I didn’t read anything else of the discussion, but just saw that I know an example for this)
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 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
participants (2)
-
Olaf Klinke
-
Sven Bartscher