Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides utilities for converting between computations
parameterized via two different typeclasses, both of which can be used to
abstract over monad transformer stacks with IO
at the base. Unfortunately,
both classes are frequently used in the Haskell ecosystem, since they have
minor differences:
MonadIO
comes from thebase
package (as ofbase
version 4.9.0.0), and it provides aliftIO
operation. It is an extremely simple typeclass, focusing exclusively on liftingIO
actions through transformer stacks withIO
at the base.MonadBase
comes from thetransformers-base
package, and it is a generalized version ofMonadIO
. It provides a more generalliftBase
function, which allows lifting to an arbitrary base monad.Generally, this additional power isn’t especially useful, but
MonadBase
appears most often throughMonadBaseControl
, a subclass from themonad-control
package that enables lifting operations that accept an action in negative position. This class has noIO
-specialized equivalent (not directly, at least), so it often appears in lifted “control” operations.
Due to these typeclasses being unrelated, it’s not entirely uncommon to end up
with type signatures like (
,
which are a little silly, since MonadIO
m, MonadBaseControl
IO
m) => ...
really includes all
the power of MonadBaseControl
IO
MonadIO
.
To help alleviate this problem, this module provides a set of utilities for
converting between the two constraints in situations where possible. The
MonadIOAdapterT
transformer implements MonadIO
in terms of
, and the MonadBase
IO
MonadBaseIOAdapterT
transformer implements
in terms of MonadBase
IO
MonadIO
.
- data MonadIOAdapterT m a
- adaptMonadIO :: MonadIOAdapterT m a -> m a
- data MonadBaseIOAdapterT m a
- adaptMonadBaseIO :: MonadBaseIOAdapterT m a -> m a
Adapting MonadIO in terms of MonadBase IO
data MonadIOAdapterT m a Source #
A transformer that implements MonadIO
in terms of
, simply
converting any calls to MonadBase
IO
liftIO
into calls to liftBase
. This makes it
possible to discharge MonadIO
constraints by converting them into
constraints. For example, given a value with the following
type:MonadBase
IO
foo :: MonadIO
m => m ()
…it’s possible to convert its type signature using adaptMonadIO
:
adaptMonadIO
foo ::MonadBase
IO
m => m ()
MonadTrans MonadIOAdapterT Source # | |
MonadTransControl MonadIOAdapterT Source # | |
MonadBaseControl b m => MonadBaseControl b (MonadIOAdapterT m) Source # | |
MonadBase b m => MonadBase b (MonadIOAdapterT m) Source # | |
MonadError e m => MonadError e (MonadIOAdapterT m) Source # | |
MonadReader r m => MonadReader r (MonadIOAdapterT m) Source # | |
MonadState s m => MonadState s (MonadIOAdapterT m) Source # | |
MonadWriter w m => MonadWriter w (MonadIOAdapterT m) Source # | |
Monad m => Monad (MonadIOAdapterT m) Source # | |
Functor m => Functor (MonadIOAdapterT m) Source # | |
Applicative m => Applicative (MonadIOAdapterT m) Source # | |
MonadBase IO m => MonadIO (MonadIOAdapterT m) Source # | |
MonadThrow m => MonadThrow (MonadIOAdapterT m) Source # | |
MonadCatch m => MonadCatch (MonadIOAdapterT m) Source # | |
MonadMask m => MonadMask (MonadIOAdapterT m) Source # | |
MonadLogger m => MonadLogger (MonadIOAdapterT m) Source # | |
type StT MonadIOAdapterT a Source # | |
type StM (MonadIOAdapterT m) a Source # | |
adaptMonadIO :: MonadIOAdapterT m a -> m a Source #
“Runs” a MonadIOAdapterT
computation and returns the remaining
transformer stack.
Adapting MonadBase IO in terms of MonadIO
data MonadBaseIOAdapterT m a Source #
A transformer that implements MonadBase
in terms of MonadIO
, simply
converting any calls to liftBase
into calls to liftIO
. This makes it
possible to discharge
constraints by converting them into
MonadBase
IO
MonadIO
constraints. For example, given a value with the following type:
foo ::MonadBase
IO
m => m ()
…it’s possible to convert its type signature using adaptMonadIO
:
adaptMonadBaseIO
foo ::MonadIO
m => m ()
MonadTrans MonadBaseIOAdapterT Source # | |
MonadIO m => MonadBase IO (MonadBaseIOAdapterT m) Source # | |
MonadError e m => MonadError e (MonadBaseIOAdapterT m) Source # | |
MonadReader r m => MonadReader r (MonadBaseIOAdapterT m) Source # | |
MonadState s m => MonadState s (MonadBaseIOAdapterT m) Source # | |
MonadWriter w m => MonadWriter w (MonadBaseIOAdapterT m) Source # | |
Monad m => Monad (MonadBaseIOAdapterT m) Source # | |
Functor m => Functor (MonadBaseIOAdapterT m) Source # | |
Applicative m => Applicative (MonadBaseIOAdapterT m) Source # | |
MonadIO m => MonadIO (MonadBaseIOAdapterT m) Source # | |
MonadThrow m => MonadThrow (MonadBaseIOAdapterT m) Source # | |
MonadCatch m => MonadCatch (MonadBaseIOAdapterT m) Source # | |
MonadMask m => MonadMask (MonadBaseIOAdapterT m) Source # | |
MonadLogger m => MonadLogger (MonadBaseIOAdapterT m) Source # | |
adaptMonadBaseIO :: MonadBaseIOAdapterT m a -> m a Source #
“Runs” a MonadBaseIOAdapterT
computation and returns the remaining
transformer stack.