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 breturn :: a -> m a
class Functor m => Monad m where
(>>=) :: 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 .