Proposal: Applicative => Monad: Call for consensus

Maciej Piechotka uzytkownik2 at gmail.com
Tue Jan 4 13:59:54 CET 2011


On Tue, 2011-01-04 at 13:49 +0100, Gábor Lehel wrote:
> >> 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. 

+1. I also find join easier. 

This particular change can be done right now without breaking anything I
believe [even if whole proposal is rejected]:

class Monad m where
    return :: a -> m a
    (>>=) :: m a -> (a -> m b) -> m b
    (>>) :: m a -> m b -> m b
    join :: m (m a) -> m a
    join = (>>= id)

mkBind :: Monad m => ((a -> b) -> m a -> m b) -> m a -> (a -> m b)
       -> m b
mkBind map mv mf = join (map mf mv)

...

instance Monad m where
   join = ...
   return = ...
   (>>=) = mkBind fmap

However with this proposal it is even nicer (no need for mkBind).

Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110104/c58de534/attachment.pgp>


More information about the Libraries mailing list