From: simonpj@microsoft.com Date: Sat, 27 Oct 2007 15:45:51 +0000 (+0000) Subject: Add anyM to IOEnv X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=7018caf5ea3319d575823641d03e172b85ea8791 Add anyM to IOEnv --- diff --git a/compiler/utils/IOEnv.hs b/compiler/utils/IOEnv.hs index fc513a0..a87413b 100644 --- a/compiler/utils/IOEnv.hs +++ b/compiler/utils/IOEnv.hs @@ -17,7 +17,7 @@ module IOEnv ( -- Standard combinators, specialised returnM, thenM, thenM_, failM, failWithM, mappM, mappM_, mapSndM, sequenceM, sequenceM_, - foldlM, foldrM, + foldlM, foldrM, anyM, mapAndUnzipM, mapAndUnzip3M, checkM, ifM, zipWithM, zipWithM_, @@ -176,6 +176,7 @@ mapAndUnzipM :: (a -> IOEnv env (b,c)) -> [a] -> IOEnv env ([b],[c]) mapAndUnzip3M :: (a -> IOEnv env (b,c,d)) -> [a] -> IOEnv env ([b],[c],[d]) checkM :: Bool -> IOEnv env a -> IOEnv env () -- Perform arg if bool is False ifM :: Bool -> IOEnv env a -> IOEnv env () -- Perform arg if bool is True +anyM :: (a -> IOEnv env Bool) -> [a] -> IOEnv env Bool mappM f [] = return [] mappM f (x:xs) = do { r <- f x; rs <- mappM f xs; return (r:rs) } @@ -186,6 +187,10 @@ mapSndM f ((a,b):xs) = do { c <- f b; rs <- mapSndM f xs; return ((a,c):rs) } mappM_ f [] = return () mappM_ f (x:xs) = f x >> mappM_ f xs +anyM f [] = return False +anyM f (x:xs) = do { b <- f x; if b then return True + else anyM f xs } + zipWithM :: (a -> b -> IOEnv env c) -> [a] -> [b] -> IOEnv env [c] zipWithM f [] bs = return [] zipWithM f as [] = return []