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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

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

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
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|

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

Conal Elliott
Also, return, ap, liftM, liftM2, ....  Already discussed?

On Fri, Jan 30, 2009 at 9:03 AM, Thomas Davie <[hidden email]> wrote:
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
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-prime


_______________________________________________
Haskell-prime mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|

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

Achim Schneider
Conal Elliott <[hidden email]> wrote:

> 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.


_______________________________________________
Haskell-prime mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|

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

Conal Elliott
Exactly.  and <*>, liftA, liftA2, ...

On Fri, Mar 20, 2009 at 3:02 PM, Achim Schneider <[hidden email]> wrote:
Conal Elliott <[hidden email]> wrote:

> 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



_______________________________________________
Haskell-prime mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|

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

Achim Schneider
Conal Elliott <[hidden email]> 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.

--
(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.


_______________________________________________
Haskell-prime mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|

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

Ashley Yakeley
Achim Schneider wrote:
 > Conal Elliott <[hidden email]> 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

_______________________________________________
Haskell-prime mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-prime
Reply | Threaded
Open this post in threaded view
|

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

Ashley Yakeley
Oops, I don't seem to be paying attention to dates on posts.

--
Ashley Yakeley

_______________________________________________
Haskell-prime mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-prime