Proposal: Applicative => Monad: Call for consensus
Gábor Lehel
illissius at gmail.com
Tue Jan 4 13:49:01 CET 2011
On Tue, Jan 4, 2011 at 1:25 PM, Ian Lynagh <igloo at earth.li> wrote:
> On Mon, Jan 03, 2011 at 11:30:44PM +0100, Bas van Dijk wrote:
>>
>> 1) Make Applicative a superclass of Monad. So the new hierarchy becomes:
>>
>> class Applicative m => Monad m where
>
>> Now which notable things are not included in the patch for base:
>>
>> * fmap is not renamed to map.
>> * return and (>>) are not removed as a method.
>> * fail is not removed as a method.
>> * All the liftM functions are not removed in favour of fmap and liftAs.
>>
>> I think these are better left as separate proposals.
>
> OK, but I think it would be good to get any changes into a single
> release, so people only need to fix their instances once.
>
>> (>>=) :: forall a b. m a -> (a -> m b) -> m b
>> m >>= f = join $ fmap f m
>>
>> join :: m (m a) -> m a
>> join m = m >>= id
>
> Have you got an example of a Monad for which you'd want to define join
> but not (>>=)?
>
>>
>> (>>) :: forall a b. m a -> m b -> m b
>> (>>) = (*>)
>>
>> return :: a -> m a
>> return = pure
>>
>> fail :: String -> m a
>> fail s = error s
>>
>> 2) Make 'join' a method of Monad.
>
> Why?
Of course I'm only a sample size of one, but I find join a lot easier
to think about and implement than (>>=). Even trying to look at it
objectively and factor out my own potential idiosyncracies, it's
obvious that it only has one argument to (>>=)'s two, and the type
signature looks a lot more straightforward any way I slice it. I was
very glad to see this proposal to make it possible to define a Monad
using return (pure), fmap, and join, rather than return and (>>=).
I also recall reading somewhere that mathematically speaking join is
the more significant operation but I'll leave that to the experts.
>
>> 6) Add a Monad instance for ((,) a): (There are already Functor and
>> Applicative instances for it.)
>>
>> (Maybe this one should be left out of the patch)
>
> It does sound like a separate issue.
>
>
> Thanks
> Ian
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
--
Work is punishment for failing to procrastinate effectively.
More information about the Libraries
mailing list