[Haskell-cafe] Why Kleisli composition is not in the Monad signature?

Brent Yorgey byorgey at seas.upenn.edu
Fri Nov 30 15:51:03 CET 2012


On Fri, Nov 30, 2012 at 02:33:54AM +0100, Ben Franksen wrote:
> Brent Yorgey wrote:
> > On Thu, Nov 29, 2012 at 03:52:58AM +0100, Ben Franksen wrote:
> >> Tony Morris wrote:
> >> > As a side note, I think a direct superclass of Functor for Monad is not
> >> > a good idea, just sayin'
> >> > 
> >> > class Functor f where
> >> >   fmap :: (a -> b) -> f a -> f b
> >> > 
> >> > class Functor f => Apply f where
> >> >   (<*>) :: f (a -> b) -> f a -> f b
> >> > 
> >> > class Apply f => Bind f where
> >> >   (=<<) :: (a -> f b) -> f a -> f b
> >> > 
> >> > class Apply f => Applicative f where
> >> >   unit :: a -> f a
> >> > 
> >> > class (Applicative f, Bind f) => Monad f where
> >> > 
> >> > Same goes for Comonad (e.g. [] has (=<<) but not counit)
> >> > ... and again for Monoid, Category, I could go on...
> >> 
> >> Hi Tony
> >> 
> >> even though I dismissed your mentioning this on the Haskell' list, I do 
> have 
> >> to admit that the proposal has a certain elegance. However, before I buy 
> >> into this scheme, I'd like to see some striking examples for types with 
> >> natural (or at least useful) Apply and Bind instances that cannot be made 
> >> Applicative resp. Monad. 
> > 
> > Try writing an Applicative instances for (Data.Map.Map k).  It can't
> > be done, but the Apply instance is (I would argue) both natural and 
> useful.
> 
> I see. So there is one example. Are there more? I'd like to get a feeling 
> for the abstraction and this is hard if there is only a single example.

Any data type which admits structures of arbitrary but *only finite*
size has a natural "zippy" Apply instance but no Applicative (since
pure would have to be an infinite structure).  The Map instance I
mentioned above falls in this category.  Though I guess I'm having
trouble coming up with other examples, but I'm sure some exist.  Maybe
Edward knows of other examples.

-Brent



More information about the Haskell-Cafe mailing list