[Proposal] Move most of Control.Monad to Control.Applicative

Hi, Most of Control.Monad doesn't actually rely on Monads, but instead Applicatives. Data.Traversable fixes this in a lot of cases, but it would be nice to have the 'standard' functions as general as possible. My quick reading of Control.Monad says these at least should fall victim to demotion to applicatives: mapA :: (Applicative f) => (a -> f b) -> [a] -> f [b] mapA_ :: (Applicative f) => (a -> f b) -> [a] -> f () sequence :: (Applicative f) => [f a] -> f [a] sequence_ :: (Applicative f) => [f a] -> f () filterA :: (Applicative f) => (a -> f Bool) -> [a] -> f [a] mapAndUnzipA :: (Applicative f) => (a -> f (b,c)) -> [a] -> f ([b], [c]) zipWithA :: (Applicative f) => (a -> b -> f c) -> [a] -> [b] -> f [c] zipWithA_ :: (Applicative f) => (a -> b -> f c) -> [a] -> [b] -> f () replicateA :: (Applicative f) => Int -> f a -> f [a] replicateA_ :: (Applicative f) => Int -> f a -> f () when :: (Applicative f) => Bool -> f () -> f () unless :: (Applicative f) => Bool -> f () -> f () I may have missed some. Bob

Also, return, ap, liftM, liftM2, .... Already discussed?
On Fri, Jan 30, 2009 at 9:03 AM, Thomas Davie
Hi, Most of Control.Monad doesn't actually rely on Monads, but instead Applicatives. Data.Traversable fixes this in a lot of cases, but it would be nice to have the 'standard' functions as general as possible.
My quick reading of Control.Monad says these at least should fall victim to demotion to applicatives:
mapA :: (Applicative f) => (a -> f b) -> [a] -> f [b] mapA_ :: (Applicative f) => (a -> f b) -> [a] -> f () sequence :: (Applicative f) => [f a] -> f [a] sequence_ :: (Applicative f) => [f a] -> f ()
filterA :: (Applicative f) => (a -> f Bool) -> [a] -> f [a] mapAndUnzipA :: (Applicative f) => (a -> f (b,c)) -> [a] -> f ([b], [c]) zipWithA :: (Applicative f) => (a -> b -> f c) -> [a] -> [b] -> f [c] zipWithA_ :: (Applicative f) => (a -> b -> f c) -> [a] -> [b] -> f () replicateA :: (Applicative f) => Int -> f a -> f [a] replicateA_ :: (Applicative f) => Int -> f a -> f ()
when :: (Applicative f) => Bool -> f () -> f () unless :: (Applicative f) => Bool -> f () -> f ()
I may have missed some.
Bob _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime

Conal Elliott
return
pure! There's the Other Prelude[1], which is enough fun to be taken seriously. [1] http://www.haskell.org/haskellwiki/The_Other_Prelude -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited.

Exactly. and <*>, liftA, liftA2, ...
On Fri, Mar 20, 2009 at 3:02 PM, Achim Schneider
Conal Elliott
wrote: return
pure!
There's the Other Prelude[1], which is enough fun to be taken seriously.

Conal Elliott
Exactly. and <*>, liftA, liftA2, ...
I think it's safe to say that there's a general consensus that Functor not being a superclass of Monad is a regrettable historical ward that ought to be fixed... the problem with fixing it is that it opens up a whole can of worms, only starting with whether or not Pointed should be a class by itself: While the Proper Way might be to include all of category-extras in the Prelude, the Proper Way might not at all be the Right Way. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited.

Achim Schneider wrote:
Conal Elliott
wrote: Exactly. and <*>, liftA, liftA2, ...
I think it's safe to say that there's a general consensus that Functor not being a superclass of Monad is a regrettable historical ward that ought to be fixed... the problem with fixing it is that it opens up a whole can of worms, only starting with whether or not Pointed should be a class by itself: While the Proper Way might be to include all of category-extras in the Prelude, the Proper Way might not at all be the Right Way.
I proposed this a year ago, but got no traction because people insisted on some extension called "class aliases" so they wouldn't have to write this piece of code: class Functor MyMonad where fmap = liftM class Applicative MyMonad where <*> = ap See http://thread.gmane.org/gmane.comp.lang.haskell.prime/2641/ -- Ashley Yakeley
participants (4)
-
Achim Schneider
-
Ashley Yakeley
-
Conal Elliott
-
Thomas Davie