monad-io-adapter-0.1.0.0: Adapters between MonadIO and MonadBase IO.

Safe HaskellNone
LanguageHaskell2010

Control.Monad.IO.Adapter

Contents

Description

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 the base package (as of base version 4.9.0.0), and it provides a liftIO operation. It is an extremely simple typeclass, focusing exclusively on lifting IO actions through transformer stacks with IO at the base.
  • MonadBase comes from the transformers-base package, and it is a generalized version of MonadIO. It provides a more general liftBase function, which allows lifting to an arbitrary base monad.

    Generally, this additional power isn’t especially useful, but MonadBase appears most often through MonadBaseControl, a subclass from the monad-control package that enables lifting operations that accept an action in negative position. This class has no IO-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 (MonadIO m, MonadBaseControl IO m) => ..., which are a little silly, since MonadBaseControl IO really includes all the power of 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 MonadBase IO, and the MonadBaseIOAdapterT transformer implements MonadBase IO in terms of MonadIO.

Synopsis

Adapting MonadIO in terms of MonadBase IO

data MonadIOAdapterT m a Source #

A transformer that implements MonadIO in terms of MonadBase IO, simply converting any calls to liftIO into calls to liftBase. This makes it possible to discharge MonadIO constraints by converting them into MonadBase IO constraints. For example, given a value with the following type:

foo :: MonadIO m => m ()

…it’s possible to convert its type signature using adaptMonadIO:

adaptMonadIO foo :: MonadBase IO m => m ()

Instances

MonadTrans MonadIOAdapterT Source # 

Methods

lift :: Monad m => m a -> MonadIOAdapterT m a #

MonadTransControl MonadIOAdapterT Source # 

Associated Types

type StT (MonadIOAdapterT :: (* -> *) -> * -> *) a :: * #

MonadBaseControl b m => MonadBaseControl b (MonadIOAdapterT m) Source # 

Associated Types

type StM (MonadIOAdapterT m :: * -> *) a :: * #

MonadBase b m => MonadBase b (MonadIOAdapterT m) Source # 

Methods

liftBase :: b α -> MonadIOAdapterT m α #

MonadError e m => MonadError e (MonadIOAdapterT m) Source # 
MonadReader r m => MonadReader r (MonadIOAdapterT m) Source # 

Methods

ask :: MonadIOAdapterT m r #

local :: (r -> r) -> MonadIOAdapterT m a -> MonadIOAdapterT m a #

reader :: (r -> a) -> MonadIOAdapterT m a #

MonadState s m => MonadState s (MonadIOAdapterT m) Source # 

Methods

get :: MonadIOAdapterT m s #

put :: s -> MonadIOAdapterT m () #

state :: (s -> (a, s)) -> MonadIOAdapterT m a #

MonadWriter w m => MonadWriter w (MonadIOAdapterT m) Source # 

Methods

writer :: (a, w) -> MonadIOAdapterT m a #

tell :: w -> MonadIOAdapterT m () #

listen :: MonadIOAdapterT m a -> MonadIOAdapterT m (a, w) #

pass :: MonadIOAdapterT m (a, w -> w) -> MonadIOAdapterT m a #

Monad m => Monad (MonadIOAdapterT m) Source # 
Functor m => Functor (MonadIOAdapterT m) Source # 

Methods

fmap :: (a -> b) -> MonadIOAdapterT m a -> MonadIOAdapterT m b #

(<$) :: a -> MonadIOAdapterT m b -> MonadIOAdapterT m a #

Applicative m => Applicative (MonadIOAdapterT m) Source # 
MonadBase IO m => MonadIO (MonadIOAdapterT m) Source # 

Methods

liftIO :: IO a -> MonadIOAdapterT m a #

MonadThrow m => MonadThrow (MonadIOAdapterT m) Source # 

Methods

throwM :: Exception e => e -> MonadIOAdapterT m a #

MonadCatch m => MonadCatch (MonadIOAdapterT m) Source # 

Methods

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

MonadMask m => MonadMask (MonadIOAdapterT m) Source # 

Methods

mask :: ((forall a. MonadIOAdapterT m a -> MonadIOAdapterT m a) -> MonadIOAdapterT m b) -> MonadIOAdapterT m b #

uninterruptibleMask :: ((forall a. MonadIOAdapterT m a -> MonadIOAdapterT m a) -> MonadIOAdapterT m b) -> MonadIOAdapterT m b #

MonadLogger m => MonadLogger (MonadIOAdapterT m) Source # 

Methods

monadLoggerLog :: ToLogStr msg => Loc -> LogSource -> LogLevel -> msg -> MonadIOAdapterT m () #

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 MonadBase IO constraints by converting them into 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 ()

Instances

MonadTrans MonadBaseIOAdapterT Source # 

Methods

lift :: Monad m => m a -> MonadBaseIOAdapterT m a #

MonadIO m => MonadBase IO (MonadBaseIOAdapterT m) Source # 

Methods

liftBase :: IO α -> MonadBaseIOAdapterT m α #

MonadError e m => MonadError e (MonadBaseIOAdapterT m) Source # 
MonadReader r m => MonadReader r (MonadBaseIOAdapterT m) Source # 

Methods

ask :: MonadBaseIOAdapterT m r #

local :: (r -> r) -> MonadBaseIOAdapterT m a -> MonadBaseIOAdapterT m a #

reader :: (r -> a) -> MonadBaseIOAdapterT m a #

MonadState s m => MonadState s (MonadBaseIOAdapterT m) Source # 

Methods

get :: MonadBaseIOAdapterT m s #

put :: s -> MonadBaseIOAdapterT m () #

state :: (s -> (a, s)) -> MonadBaseIOAdapterT m a #

MonadWriter w m => MonadWriter w (MonadBaseIOAdapterT m) Source # 
Monad m => Monad (MonadBaseIOAdapterT m) Source # 
Functor m => Functor (MonadBaseIOAdapterT m) Source # 

Methods

fmap :: (a -> b) -> MonadBaseIOAdapterT m a -> MonadBaseIOAdapterT m b #

(<$) :: a -> MonadBaseIOAdapterT m b -> MonadBaseIOAdapterT m a #

Applicative m => Applicative (MonadBaseIOAdapterT m) Source # 
MonadIO m => MonadIO (MonadBaseIOAdapterT m) Source # 

Methods

liftIO :: IO a -> MonadBaseIOAdapterT m a #

MonadThrow m => MonadThrow (MonadBaseIOAdapterT m) Source # 

Methods

throwM :: Exception e => e -> MonadBaseIOAdapterT m a #

MonadCatch m => MonadCatch (MonadBaseIOAdapterT m) Source # 
MonadMask m => MonadMask (MonadBaseIOAdapterT m) Source # 
MonadLogger m => MonadLogger (MonadBaseIOAdapterT m) Source # 

Methods

monadLoggerLog :: ToLogStr msg => Loc -> LogSource -> LogLevel -> msg -> MonadBaseIOAdapterT m () #

adaptMonadBaseIO :: MonadBaseIOAdapterT m a -> m a Source #

“Runs” a MonadBaseIOAdapterT computation and returns the remaining transformer stack.