A more generic version of mapM \begin{code} module MapG where import Array import Event class Monad d => MapG c a b d where mapG :: (a -> d b) -> c a -> d (c b) instance Monad d => MapG [] a b d where mapG = mapM instance (Ix a,Monad d) => MapG (Array a) b c d where mapG = mapGArray instance Monad d => MapG Maybe a b d where mapG f Nothing = return Nothing mapG f (Just a) = f a >>= return . Just mapGArray :: (Monad d,Ix c) => (a -> d b) -> Array c a -> d (Array c b) mapGArray f arr = do vals <- mapM (\n -> do v <- f $ arr ! n return (n,v)) (range $ bounds arr) return $ array (bounds arr) vals instance MapG Event a b IO where mapG f e = return $! withIOE e f \end{code}