foundation-0.0.17: Alternative prelude with batteries and no dependencies

Safe Haskell | None
Language | Haskell2010

Foundation.Monad

Synopsis

- class Monad m => MonadIO m where
- class Monad m => MonadFailure m where
  - type Failure (m :: * -> *) :: *
- class Monad m => MonadThrow m where
- class MonadThrow m => MonadCatch m where
- class MonadCatch m => MonadBracket m where
- class MonadTrans trans where
- newtype Identity a :: * -> * = Identity {
  - runIdentity :: a
  }
- replicateM :: Applicative m => CountOf a -> m a -> m [a]

# Documentation

class Monad m => MonadIO m where #

Monads in which `IO` computations may be embedded. Any monad built by applying a sequence of monad transformers to the `IO` monad will be an instance of this class.

Instances should satisfy the following laws, which state that `liftIO` is a transformer of monads:

-     liftIO . return = return

-     liftIO (m >>= f) = liftIO m >>= (liftIO . f)

Minimal complete definition

liftIO

Methods

liftIO :: IO a -> m a #

Lift a computation from the `IO` monad.

Instances

MonadIO IO |
Methods liftIO :: IO a -> IO a #
MonadIO m => MonadIO (ResourceT m) # |
Methods liftIO :: IO a -> ResourceT m a #
MonadIO m => MonadIO (ReaderT r m) # |
Methods liftIO :: IO a -> ReaderT r m a #
MonadIO m => MonadIO (ExceptT e m) # |
Methods liftIO :: IO a -> ExceptT e m a #
(Functor m, MonadIO m) => MonadIO (StateT s m) # |
Methods liftIO :: IO a -> StateT s m a #
MonadIO m => MonadIO (Conduit i o m) # |
Methods liftIO :: IO a -> Conduit i o m a #

class Monad m => MonadFailure m where #

Monad that can represent failure

Similar to MonadFail but with a parametrized Failure linked to the Monad

Minimal complete definition

mFail

Associated Types

type Failure (m :: * -> *) :: * #

The associated type with the MonadFailure, representing what failure can be encoded in this monad

Methods

mFail :: Failure m -> m () #

Raise a Failure through a monad.

Instances

MonadFailure Maybe |
Associated Types type Failure (Maybe :: * -> *) :: * # Methods mFail :: Failure Maybe -> Maybe () #
MonadFailure (Either a) |
Associated Types type Failure (Either a :: * -> *) :: * # Methods mFail :: Failure (Either a) -> Either a () #
MonadFailure m => MonadFailure (ReaderT r m) # |
Associated Types type Failure (ReaderT r m :: * -> *) :: * # Methods mFail :: Failure (ReaderT r m) -> ReaderT r m () #
Monad m => MonadFailure (ExceptT e m) # |
Associated Types type Failure (ExceptT e m :: * -> *) :: * # Methods mFail :: Failure (ExceptT e m) -> ExceptT e m () #
(Functor m, MonadFailure m) => MonadFailure (StateT s m) # |
Associated Types type Failure (StateT s m :: * -> *) :: * # Methods mFail :: Failure (StateT s m) -> StateT s m () #
MonadFailure m => MonadFailure (Conduit i o m) # |
Associated Types type Failure (Conduit i o m :: * -> *) :: * # Methods mFail :: Failure (Conduit i o m) -> Conduit i o m () #
Monad state => MonadFailure (Builder collection mutCollection step state err) |
Associated Types type Failure (Builder collection mutCollection step state err :: * -> *) :: * # Methods mFail :: Failure (Builder collection mutCollection step state err) -> Builder collection mutCollection step state err () #

class Monad m => MonadThrow m where Source #

Monad that can throw exception

Minimal complete definition

throw

Methods

throw :: Exception e => e -> m a Source #

Throw immediatity an exception. Only a `MonadCatch` monad will be able to catch the exception using `catch`

Instances

MonadThrow IO Source # |
Methods throw :: Exception e => e -> IO a Source #
MonadThrow m => MonadThrow (ResourceT m) Source # |
Methods throw :: Exception e => e -> ResourceT m a Source #
MonadThrow m => MonadThrow (ReaderT r m) Source # |
Methods throw :: Exception e => e -> ReaderT r m a Source #
(Functor m, MonadThrow m) => MonadThrow (StateT s m) Source # |
Methods throw :: Exception e => e -> StateT s m a Source #
MonadThrow m => MonadThrow (Conduit i o m) Source # |
Methods throw :: Exception e => e -> Conduit i o m a Source #

class MonadThrow m => MonadCatch m where Source #

Monad that can catch exception

Minimal complete definition

catch

Methods

catch :: Exception e => m a -> (e -> m a) -> m a Source #

Instances

MonadCatch IO Source # |
Methods catch :: Exception e => IO a -> (e -> IO a) -> IO a Source #
MonadCatch m => MonadCatch (ResourceT m) Source # |
Methods catch :: Exception e => ResourceT m a -> (e -> ResourceT m a) -> ResourceT m a Source #
MonadCatch m => MonadCatch (ReaderT r m) Source # |
Methods catch :: Exception e => ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a Source #
(Functor m, MonadCatch m) => MonadCatch (StateT s m) Source # |
Methods catch :: Exception e => StateT s m a -> (e -> StateT s m a) -> StateT s m a Source #
MonadCatch m => MonadCatch (Conduit i o m) Source # |
Methods catch :: Exception e => Conduit i o m a -> (e -> Conduit i o m a) -> Conduit i o m a Source #

class MonadCatch m => MonadBracket m where Source #

Monad that can ensure cleanup actions are performed even in the case of exceptions, both synchronous and asynchronous. This usually excludes continuation-based monads.

Minimal complete definition

generalBracket

Methods

generalBracket :: m a -> (a -> b -> m ignored1) -> (a -> SomeException -> m ignored2) -> (a -> m b) -> m b Source #

A generalized version of the standard bracket function which allows distinguishing different exit cases.

Instances

MonadBracket IO Source # |
Methods generalBracket :: IO a -> (a -> b -> IO ignored1) -> (a -> SomeException -> IO ignored2) -> (a -> IO b) -> IO b Source #
MonadBracket m => MonadBracket (ResourceT m) Source # |
Methods generalBracket :: ResourceT m a -> (a -> b -> ResourceT m ignored1) -> (a -> SomeException -> ResourceT m ignored2) -> (a -> ResourceT m b) -> ResourceT m b Source #
MonadBracket m => MonadBracket (ReaderT r m) Source # |
Methods generalBracket :: ReaderT r m a -> (a -> b -> ReaderT r m ignored1) -> (a -> SomeException -> ReaderT r m ignored2) -> (a -> ReaderT r m b) -> ReaderT r m b Source #

class MonadTrans trans where Source #

Basic Transformer class

Minimal complete definition

lift

Methods

lift :: Monad m => m a -> trans m a Source #

Lift a computation from an inner monad to the current transformer monad

Instances

MonadTrans ResourceT Source # |
Methods lift :: Monad m => m a -> ResourceT m a Source #
MonadTrans (ReaderT r) Source # |
Methods lift :: Monad m => m a -> ReaderT r m a Source #
MonadTrans (ExceptT e) Source # |
Methods lift :: Monad m => m a -> ExceptT e m a Source #
MonadTrans (StateT s) Source # |
Methods lift :: Monad m => m a -> StateT s m a Source #
MonadTrans (Conduit i o) Source # |
Methods lift :: Monad m => m a -> Conduit i o m a Source #

newtype Identity a :: * -> * #

Identity functor and monad. (a non-strict monad)

Since: 4.8.0.0

Constructors

Identity |

Fields

- runIdentity :: a

Instances

Monad Identity |
Methods (>>=) :: Identity a -> (a -> Identity b) -> Identity b # (>>) :: Identity a -> Identity b -> Identity b # return :: a -> Identity a # fail :: String -> Identity a #
Functor Identity |
Methods fmap :: (a -> b) -> Identity a -> Identity b # (<$) :: a -> Identity b -> Identity a #
MonadFix Identity |
Methods mfix :: (a -> Identity a) -> Identity a #
Applicative Identity |
Methods pure :: a -> Identity a # (<*>) :: Identity (a -> b) -> Identity a -> Identity b # (*>) :: Identity a -> Identity b -> Identity b # (<*) :: Identity a -> Identity b -> Identity a #
Foldable Identity |

Methods

fold :: Monoid m => Identity m -> m #

foldMap :: Monoid m => (a -> m) -> Identity a -> m #

foldr :: (a -> b -> b) -> b -> Identity a -> b #

foldr' :: (a -> b -> b) -> b -> Identity a -> b #

foldl :: (b -> a -> b) -> b -> Identity a -> b #

foldl' :: (b -> a -> b) -> b -> Identity a -> b #

foldr1 :: (a -> a -> a) -> Identity a -> a #

foldl1 :: (a -> a -> a) -> Identity a -> a #

toList :: Identity a -> [a] #

null :: Identity a -> Bool #

length :: Identity a -> Int #

elem :: Eq a => a -> Identity a -> Bool #

maximum :: Ord a => Identity a -> a #

minimum :: Ord a => Identity a -> a #

sum :: Num a => Identity a -> a #

product :: Num a => Identity a -> a #

Traversable Identity |
Methods traverse :: Applicative f => (a -> f b) -> Identity a -> f (Identity b) # sequenceA :: Applicative f => Identity (f a) -> f (Identity a) # mapM :: Monad m => (a -> m b) -> Identity a -> m (Identity b) # sequence :: Monad m => Identity (m a) -> m (Identity a) #
Generic1 Identity |
Associated Types type Rep1 (Identity :: * -> *) :: * -> * # Methods from1 :: Identity a -> Rep1 Identity a # to1 :: Rep1 Identity a -> Identity a #
MonadZip Identity |
Methods mzip :: Identity a -> Identity b -> Identity (a, b) # mzipWith :: (a -> b -> c) -> Identity a -> Identity b -> Identity c # munzip :: Identity (a, b) -> (Identity a, Identity b) #
Bounded a => Bounded (Identity a) |
Methods minBound :: Identity a # maxBound :: Identity a #
Enum a => Enum (Identity a) |
Methods succ :: Identity a -> Identity a # pred :: Identity a -> Identity a # toEnum :: Int -> Identity a # fromEnum :: Identity a -> Int # enumFrom :: Identity a -> [Identity a] # enumFromThen :: Identity a -> Identity a -> [Identity a] # enumFromTo :: Identity a -> Identity a -> [Identity a] # enumFromThenTo :: Identity a -> Identity a -> Identity a -> [Identity a] #
Eq a => Eq (Identity a) |
Methods (==) :: Identity a -> Identity a -> Bool # (/=) :: Identity a -> Identity a -> Bool #
Floating a => Floating (Identity a) |

Methods

pi :: Identity a #

exp :: Identity a -> Identity a #

log :: Identity a -> Identity a #

sqrt :: Identity a -> Identity a #

(**) :: Identity a -> Identity a -> Identity a #

logBase :: Identity a -> Identity a -> Identity a #

sin :: Identity a -> Identity a #

cos :: Identity a -> Identity a #

tan :: Identity a -> Identity a #

asin :: Identity a -> Identity a #

acos :: Identity a -> Identity a #

atan :: Identity a -> Identity a #

sinh :: Identity a -> Identity a #

cosh :: Identity a -> Identity a #

tanh :: Identity a -> Identity a #

asinh :: Identity a -> Identity a #

acosh :: Identity a -> Identity a #

atanh :: Identity a -> Identity a #

log1p :: Identity a -> Identity a #

expm1 :: Identity a -> Identity a #

log1pexp :: Identity a -> Identity a #

log1mexp :: Identity a -> Identity a #

Fractional a => Fractional (Identity a) |
Methods (/) :: Identity a -> Identity a -> Identity a # recip :: Identity a -> Identity a # fromRational :: Rational -> Identity a #
Integral a => Integral (Identity a) |
Methods quot :: Identity a -> Identity a -> Identity a # rem :: Identity a -> Identity a -> Identity a # div :: Identity a -> Identity a -> Identity a # mod :: Identity a -> Identity a -> Identity a # quotRem :: Identity a -> Identity a -> (Identity a, Identity a) # divMod :: Identity a -> Identity a -> (Identity a, Identity a) # toInteger :: Identity a -> Integer #
Data a => Data (Identity a) |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Identity a -> c (Identity a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Identity a) #

toConstr :: Identity a -> Constr #

dataTypeOf :: Identity a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Identity a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Identity a)) #

gmapT :: (forall b. Data b => b -> b) -> Identity a -> Identity a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Identity a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Identity a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Identity a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Identity a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) #

Num a => Num (Identity a) |
Methods (+) :: Identity a -> Identity a -> Identity a # (-) :: Identity a -> Identity a -> Identity a # (*) :: Identity a -> Identity a -> Identity a # negate :: Identity a -> Identity a # abs :: Identity a -> Identity a # signum :: Identity a -> Identity a # fromInteger :: Integer -> Identity a #
Ord a => Ord (Identity a) |
Methods compare :: Identity a -> Identity a -> Ordering # (<) :: Identity a -> Identity a -> Bool # (<=) :: Identity a -> Identity a -> Bool # (>) :: Identity a -> Identity a -> Bool # (>=) :: Identity a -> Identity a -> Bool # max :: Identity a -> Identity a -> Identity a # min :: Identity a -> Identity a -> Identity a #
Read a => Read (Identity a) | This instance would be equivalent to the derived instances of the `Identity` newtype if the `runIdentity` field were removed
Methods readsPrec :: Int -> ReadS (Identity a) # readList :: ReadS [Identity a] # readPrec :: ReadPrec (Identity a) # readListPrec :: ReadPrec [Identity a] #
Real a => Real (Identity a) |
Methods toRational :: Identity a -> Rational #
RealFloat a => RealFloat (Identity a) |

Methods

floatRadix :: Identity a -> Integer #

floatDigits :: Identity a -> Int #

floatRange :: Identity a -> (Int, Int) #

decodeFloat :: Identity a -> (Integer, Int) #

encodeFloat :: Integer -> Int -> Identity a #

exponent :: Identity a -> Int #

significand :: Identity a -> Identity a #

scaleFloat :: Int -> Identity a -> Identity a #

isNaN :: Identity a -> Bool #

isInfinite :: Identity a -> Bool #

isDenormalized :: Identity a -> Bool #

isNegativeZero :: Identity a -> Bool #

isIEEE :: Identity a -> Bool #

atan2 :: Identity a -> Identity a -> Identity a #

RealFrac a => RealFrac (Identity a) |
Methods properFraction :: Integral b => Identity a -> (b, Identity a) # truncate :: Integral b => Identity a -> b # round :: Integral b => Identity a -> b # ceiling :: Integral b => Identity a -> b # floor :: Integral b => Identity a -> b #
Show a => Show (Identity a) | This instance would be equivalent to the derived instances of the `Identity` newtype if the `runIdentity` field were removed
Methods showsPrec :: Int -> Identity a -> ShowS # show :: Identity a -> String # showList :: [Identity a] -> ShowS #
Ix a => Ix (Identity a) |
Methods range :: (Identity a, Identity a) -> [Identity a] # index :: (Identity a, Identity a) -> Identity a -> Int # unsafeIndex :: (Identity a, Identity a) -> Identity a -> Int inRange :: (Identity a, Identity a) -> Identity a -> Bool # rangeSize :: (Identity a, Identity a) -> Int # unsafeRangeSize :: (Identity a, Identity a) -> Int
IsString a => IsString (Identity a) |
Methods fromString :: String -> Identity a #
Generic (Identity a) |
Associated Types type Rep (Identity a) :: * -> * # Methods from :: Identity a -> Rep (Identity a) x # to :: Rep (Identity a) x -> Identity a #
Semigroup a => Semigroup (Identity a) |
Methods (<>) :: Identity a -> Identity a -> Identity a # sconcat :: NonEmpty (Identity a) -> Identity a # stimes :: Integral b => b -> Identity a -> Identity a #
Monoid a => Monoid (Identity a) |
Methods mempty :: Identity a # mappend :: Identity a -> Identity a -> Identity a # mconcat :: [Identity a] -> Identity a #
Storable a => Storable (Identity a) |
Methods sizeOf :: Identity a -> Int # alignment :: Identity a -> Int # peekElemOff :: Ptr (Identity a) -> Int -> IO (Identity a) # pokeElemOff :: Ptr (Identity a) -> Int -> Identity a -> IO () # peekByteOff :: Ptr b -> Int -> IO (Identity a) # pokeByteOff :: Ptr b -> Int -> Identity a -> IO () # peek :: Ptr (Identity a) -> IO (Identity a) # poke :: Ptr (Identity a) -> Identity a -> IO () #
Bits a => Bits (Identity a) |

Methods

(.&.) :: Identity a -> Identity a -> Identity a #

(.|.) :: Identity a -> Identity a -> Identity a #

xor :: Identity a -> Identity a -> Identity a #

complement :: Identity a -> Identity a #

shift :: Identity a -> Int -> Identity a #

rotate :: Identity a -> Int -> Identity a #

zeroBits :: Identity a #

bit :: Int -> Identity a #

setBit :: Identity a -> Int -> Identity a #

clearBit :: Identity a -> Int -> Identity a #

complementBit :: Identity a -> Int -> Identity a #

testBit :: Identity a -> Int -> Bool #

bitSizeMaybe :: Identity a -> Maybe Int #

bitSize :: Identity a -> Int #

isSigned :: Identity a -> Bool #

shiftL :: Identity a -> Int -> Identity a #

unsafeShiftL :: Identity a -> Int -> Identity a #

shiftR :: Identity a -> Int -> Identity a #

unsafeShiftR :: Identity a -> Int -> Identity a #

rotateL :: Identity a -> Int -> Identity a #

rotateR :: Identity a -> Int -> Identity a #

popCount :: Identity a -> Int #

FiniteBits a => FiniteBits (Identity a) |
Methods finiteBitSize :: Identity a -> Int # countLeadingZeros :: Identity a -> Int # countTrailingZeros :: Identity a -> Int #
type Rep1 Identity |
type Rep1 Identity = D1 (MetaData "Identity" "Data.Functor.Identity" "base" True) (C1 (MetaCons "Identity" PrefixI True) (S1 (MetaSel (Just Symbol "runIdentity") NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1))
type Rep (Identity a) |
type Rep (Identity a) = D1 (MetaData "Identity" "Data.Functor.Identity" "base" True) (C1 (MetaCons "Identity" PrefixI True) (S1 (MetaSel (Just Symbol "runIdentity") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))

replicateM :: Applicative m => CountOf a -> m a -> m [a] Source #

``replicateM` n act` performs the action `n` times, gathering the results.