From 57050fbdad60a00ca9edaa2872dcf2c86b8cf094 Mon Sep 17 00:00:00 2001 From: simonpj Date: Thu, 25 Nov 1999 10:36:48 +0000 Subject: [PATCH] [project @ 1999-11-25 10:36:48 by simonpj] Express sequence in terms of foldr --- ghc/lib/std/Monad.lhs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ghc/lib/std/Monad.lhs b/ghc/lib/std/Monad.lhs index b1c5a9c..4c8c3ed 100644 --- a/ghc/lib/std/Monad.lhs +++ b/ghc/lib/std/Monad.lhs @@ -88,12 +88,14 @@ instance MonadPlus Maybe where -- mapM_ :: Monad m => (a -> m b) -> [a] -> m () #else sequence :: Monad m => [m a] -> m [a] -sequence [] = return [] -sequence (m:ms) = do { x <- m; xs <- sequence ms; return (x:xs) } +{-# INLINE sequence #-} +sequence ms = foldr k (return []) ms + where + k m m' = do { x <- m; xs <- m'; return (x:xs) } sequence_ :: Monad m => [m a] -> m () {-# INLINE sequence_ #-} -sequence_ = foldr (>>) (return ()) +sequence_ ms = foldr (>>) (return ()) ms mapM :: Monad m => (a -> m b) -> [a] -> m [b] {-# INLINE mapM #-} -- 1.7.10.4