module Monad
( module Export
, Monad ((>>=), return)
, MonadFail (fail)
, MonadPlus (..)
, (=<<)
, (>=>)
, (<=<)
, (>>)
, forever
, join
, mfilter
, filterM
, mapAndUnzipM
, zipWithM
, zipWithM_
, foldM
, foldM_
, replicateM
, replicateM_
, concatMapM
, guard
, when
, unless
, allM
, anyM
, andM
, orM
, liftM
, liftM2
, liftM3
, liftM4
, liftM5
, liftM'
, liftM2'
, ap
, (<$!>)
) where
import Monad.Either as Export
import Monad.Maybe as Export
import Monad.Trans as Export
import Base (IO, seq)
import Data.List (concat)
import Prelude (Bool (..))
#if __GLASGOW_HASKELL__ >= 710
import Control.Monad hiding (fail, (<$!>))
#else
import Control.Monad hiding (fail)
#endif
#if __GLASGOW_HASKELL__ >= 800
import Control.Monad.Fail (MonadFail (..))
#else
import Prelude (String)
import qualified Prelude as P (fail)
import Text.ParserCombinators.ReadP
import Text.ParserCombinators.ReadPrec
#endif
concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM f xs = liftM concat (mapM f xs)
liftM' :: Monad m => (a -> b) -> m a -> m b
liftM' = (<$!>)
liftM2' :: Monad m => (a -> b -> c) -> m a -> m b -> m c
liftM2' f a b = do
x <- a
y <- b
let z = f x y
z `seq` return z
(<$!>) :: Monad m => (a -> b) -> m a -> m b
f <$!> m = do
x <- m
let z = f x
z `seq` return z
andM :: (Monad m) => [m Bool] -> m Bool
andM [] = return True
andM (p:ps) = do
q <- p
if q then andM ps else return False
orM :: (Monad m) => [m Bool] -> m Bool
orM [] = return False
orM (p:ps) = do
q <- p
if q then return True else orM ps
anyM :: (Monad m) => (a -> m Bool) -> [a] -> m Bool
anyM _ [] = return False
anyM p (x:xs) = do
q <- p x
if q then return True else anyM p xs
allM :: (Monad m) => (a -> m Bool) -> [a] -> m Bool
allM _ [] = return True
allM p (x:xs) = do
q <- p x
if q then allM p xs else return False
#if __GLASGOW_HASKELL__ < 800
class Monad m => MonadFail m where
fail :: String -> m a
instance MonadFail Maybe where
fail _ = Nothing
instance MonadFail [] where
fail _ = []
instance MonadFail IO where
fail = P.fail
instance MonadFail ReadPrec where
fail = P.fail
instance MonadFail ReadP where
fail = P.fail
#endif