Functor => Pointed => Applicative => Monad

John Smith voldermort at hotmail.com
Mon Nov 29 03:39:08 EST 2010


Is there any intention to reorganise the standard class hierarchy, arranging them logically instead of in order of 
invention? I plagiarised the following example from 
http://stackoverflow.com/questions/1634911/can-liftm-differ-from-lifta and Trac:

class Functor f where
     map :: (a -> b) -> f a -> f b

class Functor f => Pointed f where
     pure :: a -> f a

class Pointed f => Applicative f where
     (<*>) :: f (a -> b) -> f a -> f b
     (*>) :: f a -> f b -> f b
     (<*) :: f a -> f b -> f a

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

     f >>= x = join (fmap f x)
     m >> k = m >>= \_ -> k
     join x = x >>= id

This would eliminate the necessity of declaring a Monad instance for every Applicative, and eliminate the need for sets 
of duplicate functions such as [fmap,liftM,map,liftA], [(<*>),ap], and [concat,join].

fail should be removed from Monad; a failed pattern match could error in the same way as is does for pure code. The only 
sensible uses for fail seem to be synonyms for mzero.



More information about the Libraries mailing list