### remove duplicate mapM, sequence, ...

parent 0517c144
 ... ... @@ -69,13 +69,6 @@ f <\$> act = act >>= (\x -> return (f x)) -> ErrorT e m a -> ErrorT e m b f <*> v = f >>= (\f' -> v >>= (\x -> return (f' x))) --- Map a monadic function on all elements of a list by sequencing --- the effects. mapM :: (Error e, Monad m) => (a -> ErrorT e m b) -> [a] -> ErrorT e m [b] mapM _ [] = return [] mapM f (x:xs) = f x >>= (\x' -> (mapM f xs) >>= (\xs' -> return (x' : xs'))) --- Same as `concatMap`, but for a monadic function. concatMapM :: (Error e, Monad m) => (a -> ErrorT e m [b]) -> [a] -> ErrorT e m [b] ... ...
 ... ... @@ -44,21 +44,6 @@ put s = state (\ _ -> ((), s)) modify :: Monad m => (s -> s) -> StateT s m () modify f = state (\ s -> ((), f s)) {- instance foldable? -} sequence :: Monad m => [StateT s m a] -> StateT s m [a] sequence = foldr (\s newS -> s >>= (\a -> newS >>= (\as -> return (a:as)))) (return []) sequence_ :: Monad m => [StateT s m a] -> StateT s m () sequence_ = foldr (>>) (return ()) mapM :: Monad m => (a -> StateT s m b) -> [a] -> StateT s m [b] mapM f = sequence . (map f) mapM_ :: Monad m => (a -> StateT s m b) -> [a] -> StateT s m () mapM_ f = sequence_ . (map f) type State s a = StateT s (Identity) a runState :: State s a -> s -> (a, s) ... ... @@ -79,10 +64,3 @@ execStateT :: (Monad m) => StateT s m a -> s -> m s execStateT m s = do ~(_, s') <- runStateT m s return s' liftM :: Monad m => (a -> b) -> StateT s m a -> StateT s m b liftM f act = act >>= (return . f) liftM2 :: Monad m => (a -> b -> c) -> StateT s m a -> StateT s m b -> StateT s m c liftM2 f a b = a >>= (\x -> b >>= (\y -> return (f x y)))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment