1 -----------------------------------------------------------------------------
3 -- Module : Data.FunctorM
4 -- Copyright : (c) The University of Glasgow 2005
5 -- License : BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
11 -- fmapM generalises fmap, just as mapM generalises map.
13 -----------------------------------------------------------------------------
15 module Data.FunctorM (
22 class FunctorM f where
23 fmapM :: Monad m => (a -> m b) -> f a -> m (f b)
24 fmapM_ :: Monad m => (a -> m b) -> f a -> m ()
26 fmapM_ f t = fmapM f t >> return ()
28 instance FunctorM [] where
32 instance FunctorM Maybe where
33 fmapM _ Nothing = return Nothing
34 fmapM f (Just x) = f x >>= return . Just
36 fmapM_ _ Nothing = return ()
37 fmapM_ f (Just x) = f x >> return ()
39 instance Ix i => FunctorM (Array i) where
41 a' <- sequence [ f e >>= return . (,) i | (i,e) <- assocs a]
42 return (array (bounds a) a')