Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class Monad m => MonadIO (m :: Type -> Type) where
- class Monad m => MonadFailure (m :: Type -> Type) where
- class Monad m => MonadThrow m where
- class MonadThrow m => MonadCatch m where
- class MonadCatch m => MonadBracket m where
- generalBracket :: m a -> (a -> b -> m ignored1) -> (a -> SomeException -> m ignored2) -> (a -> m b) -> m b
- 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 :: Type -> Type) 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:
Lift a computation from the IO
monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO
is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted
, we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO ()
and
.IO
()
Luckily, we know of a function that takes an
and returns an IO
a(m a)
:
,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3
Instances
MonadIO IO | Since: base-4.9.0.0 |
Defined in Control.Monad.IO.Class | |
MonadIO m => MonadIO (ResourceT m) Source # | |
Defined in Foundation.Conduit.Internal | |
MonadIO m => MonadIO (ExceptT e m) Source # | |
Defined in Foundation.Monad.Except | |
MonadIO m => MonadIO (ReaderT r m) Source # | |
Defined in Foundation.Monad.Reader | |
(Functor m, MonadIO m) => MonadIO (StateT s m) Source # | |
Defined in Foundation.Monad.State | |
MonadIO m => MonadIO (Conduit i o m) Source # | |
Defined in Foundation.Conduit.Internal |
class Monad m => MonadFailure (m :: Type -> Type) where Source #
Monad that can represent failure
Similar to MonadFail but with a parametrized Failure linked to the Monad
type Failure (m :: Type -> Type) Source #
The associated type with the MonadFailure, representing what failure can be encoded in this monad
Instances
MonadFailure Maybe | |
MonadFailure (Either a) | |
Monad m => MonadFailure (ExceptT e m) Source # | |
MonadFailure m => MonadFailure (ReaderT r m) Source # | |
(Functor m, MonadFailure m) => MonadFailure (StateT s m) Source # | |
MonadFailure m => MonadFailure (Conduit i o m) Source # | |
Monad state => MonadFailure (Builder collection mutCollection step state err) | |
class Monad m => MonadThrow m where Source #
Monad that can throw exception
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 # | |
MonadThrow m => MonadThrow (ResourceT m) Source # | |
MonadThrow m => MonadThrow (ReaderT r m) Source # | |
(Functor m, MonadThrow m) => MonadThrow (StateT s m) Source # | |
MonadThrow m => MonadThrow (Conduit i o m) Source # | |
class MonadThrow m => MonadCatch m where Source #
Monad that can catch exception
Instances
MonadCatch IO Source # | |
MonadCatch m => MonadCatch (ResourceT m) Source # | |
MonadCatch m => MonadCatch (ReaderT r m) Source # | |
(Functor m, MonadCatch m) => MonadCatch (StateT s m) Source # | |
MonadCatch m => MonadCatch (Conduit i o m) 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.
:: m a | acquire some resource |
-> (a -> b -> m ignored1) | cleanup, no exception thrown |
-> (a -> SomeException -> m ignored2) | cleanup, some exception thrown. The exception will be rethrown |
-> (a -> m b) | inner action to perform with the resource |
-> m b |
A generalized version of the standard bracket function which allows distinguishing different exit cases.
Instances
MonadBracket IO Source # | |
Defined in Foundation.Monad.Exception generalBracket :: IO a -> (a -> b -> IO ignored1) -> (a -> SomeException -> IO ignored2) -> (a -> IO b) -> IO b Source # | |
MonadBracket m => MonadBracket (ResourceT m) Source # | |
Defined in Foundation.Conduit.Internal 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 # | |
Defined in Foundation.Monad.Reader 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
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 # | |
MonadTrans (ExceptT e) Source # | |
MonadTrans (ReaderT r) Source # | |
MonadTrans (StateT s) Source # | |
MonadTrans (Conduit i o) Source # | |
Identity functor and monad. (a non-strict monad)
Since: base-4.8.0.0
Identity | |
|
Instances
replicateM :: Applicative m => CountOf a -> m a -> m [a] Source #
performs the action replicateM
n actn
times,
gathering the results.