On Dec 11, 2007 1:29 PM, apfelmus <apfelmus@quantentunnel.de> wrote:
Without the automatic search, this is already possible

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

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

       -- aka liftM
    fmapDefault :: Monad m => (a -> b) -> m a -> m b
    fmapDefault f m = m >>= (return . f)

    instance Monad [] where
        return x = [x]
        (>>=)    = flip concatMap

    instance Functor [] where
        fmap = fmapDefault

 fmap  is already written for you, the instance declaration is only
boilerplate. I first saw this in   Data.Traversable .
 
This is pretty much how I define Functor and Applicative instances for my monads. It is admittedly irritating to have to write out the boilerplate, but  it doesn't seem irritating enough to require a language extension to eliminate.

--
Dave Menendez <dave@zednenem.com>
<http://www.eyrie.org/~zednenem/>