projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve warning for SpecConstr
[ghc-hetmet.git]
/
compiler
/
utils
/
MonadUtils.hs
diff --git
a/compiler/utils/MonadUtils.hs
b/compiler/utils/MonadUtils.hs
index
edce995
..
85d8642
100644
(file)
--- a/
compiler/utils/MonadUtils.hs
+++ b/
compiler/utils/MonadUtils.hs
@@
-13,7
+13,7
@@
module MonadUtils
, mapAccumLM
, mapSndM
, concatMapM
, mapAccumLM
, mapSndM
, concatMapM
- , anyM
+ , anyM, allM
, foldlM, foldrM
) where
, foldlM, foldrM
) where
@@
-21,7
+21,11
@@
module MonadUtils
-- Detection of available libraries
----------------------------------------------------------------------------------------
-- Detection of available libraries
----------------------------------------------------------------------------------------
+#if __GLASGOW_HASKELL__ >= 606
#define HAVE_APPLICATIVE 1
#define HAVE_APPLICATIVE 1
+#else
+#define HAVE_APPLICATIVE 0
+#endif
-- we don't depend on MTL for now
#define HAVE_MTL 0
-- we don't depend on MTL for now
#define HAVE_MTL 0
@@
-54,6
+58,10
@@
class Functor f => Applicative f where
infixl 4 <$>
infixl 4 <*>
infixl 4 <$>
infixl 4 <*>
+instance Applicative IO where
+ pure = return
+ (<*>) = ap
+
#endif
----------------------------------------------------------------------------------------
#endif
----------------------------------------------------------------------------------------
@@
-65,6
+73,7
@@
infixl 4 <*>
class Monad m => MonadIO m where
liftIO :: IO a -> m a
class Monad m => MonadIO m where
liftIO :: IO a -> m a
+instance MonadIO IO where liftIO = id
#endif
----------------------------------------------------------------------------------------
#endif
----------------------------------------------------------------------------------------
@@
-108,13
+117,18
@@
mapSndM f ((a,b):xs) = do { c <- f b; rs <- mapSndM f xs; return ((a,c):rs) }
concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM f xs = liftM concat (mapM f xs)
concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM f xs = liftM concat (mapM f xs)
--- | Monadic version of 'any', aborts the computation at the first False value
+-- | Monadic version of 'any', aborts the computation at the first @True@ value
anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool
anyM _ [] = return False
anyM f (x:xs) = do b <- f x
if b then return True
else anyM f xs
anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool
anyM _ [] = return False
anyM f (x:xs) = do b <- f x
if b then return True
else anyM f xs
+-- | Monad version of 'all', aborts the computation at the first @False@ value
+allM :: Monad m => (a -> m Bool) -> [a] -> m Bool
+allM _ [] = return True
+allM f (b:bs) = (f b) >>= (\bv -> if bv then allM f bs else return False)
+
-- | Monadic version of foldl
foldlM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
foldlM = foldM
-- | Monadic version of foldl
foldlM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
foldlM = foldM