monad-unlift-0.1.2.0: Typeclasses for representing monad transformer unlifting

Safe HaskellSafe
LanguageHaskell2010

Control.Monad.Trans.Unlift

Contents

Description

See overview in the README.md

Synopsis

Trans

class (MonadTransControl t, Forall (Identical t)) => MonadTransUnlift t Source

A monad transformer which can be unlifted, obeying the monad morphism laws.

Since 0.1.0

Instances

(MonadTransControl t, Forall * (Identical t)) => MonadTransUnlift t Source 

newtype Unlift t Source

A function which can move an action down the monad transformer stack, by providing any necessary environment to the action.

Note that, if ImpredicativeTypes worked reliably, this type wouldn't be necessary, and askUnlift would simply include a more generalized type.

Since 0.1.0

Constructors

Unlift 

Fields

unlift :: forall a n. Monad n => t n a -> n a
 

askUnlift :: forall t m. (MonadTransUnlift t, Monad m) => t m (Unlift t) Source

Get the Unlift action for the current transformer layer.

Since 0.1.0

askRun :: (MonadTransUnlift t, Monad (t m), Monad m) => t m (t m a -> m a) Source

A simplified version of askUnlift which addresses the common case where polymorphism isn't necessary.

Since 0.1.0

Base

class (MonadBaseControl b m, Forall (IdenticalBase m)) => MonadBaseUnlift b m | m -> b Source

A monad transformer stack which can be unlifted, obeying the monad morphism laws.

Since 0.1.0

Instances

(MonadBaseControl b m, Forall * (IdenticalBase m)) => MonadBaseUnlift b m Source 

newtype UnliftBase b m Source

Similar to Unlift, but instead of moving one layer down the stack, moves the action to the base monad.

Since 0.1.0

Constructors

UnliftBase 

Fields

unliftBase :: forall a. m a -> b a
 

askUnliftBase :: forall b m. MonadBaseUnlift b m => m (UnliftBase b m) Source

Get the UnliftBase action for the current transformer stack.

Since 0.1.0

askRunBase :: MonadBaseUnlift b m => m (m a -> b a) Source

A simplified version of askUnliftBase which addresses the common case where polymorphism isn't necessary.

Since 0.1.0

Reexports

class MonadTrans t where

The class of monad transformers. Instances should satisfy the following laws, which state that lift is a monad transformation:

Methods

lift :: Monad m => m a -> t m a

Lift a computation from the argument monad to the constructed monad.

Instances

MonadTrans IdentityT 
MonadTrans Free

This is not a true monad transformer. It is only a monad transformer "up to retract".

MonadTrans ListT 
MonadTrans ResourceT 
MonadTrans MaybeT 
MonadTrans (ContT r) 
MonadTrans (ReaderT r) 
MonadTrans (StateT s) 
MonadTrans (StateT s) 
MonadTrans (ExceptT e) 
Error e => MonadTrans (ErrorT e) 
Monoid w => MonadTrans (WriterT w) 
Monoid w => MonadTrans (WriterT w) 
MonadTrans (StateRefT ref s) 
MonadTrans (WriterRefT ref w) 
Monoid w => MonadTrans (RWST r w s) 
Monoid w => MonadTrans (RWST r w s) 
MonadTrans (RWSRefT refw refs r w s) 

class (Applicative b, Applicative m, Monad b, Monad m) => MonadBase b m | m -> b where

Methods

liftBase :: b α -> m α

Lift a computation from the base monad

Instances

MonadBase [] [] 
MonadBase IO IO 
MonadBase Identity Identity 
MonadBase STM STM 
MonadBase Maybe Maybe 
MonadBase b m => MonadBase b (MaybeT m) 
MonadBase b m => MonadBase b (ListT m) 
MonadBase b m => MonadBase b (IdentityT m) 
MonadBase b m => MonadBase b (ResourceT m) 
(Monoid w, MonadBase b m) => MonadBase b (WriterT w m) 
(Monoid w, MonadBase b m) => MonadBase b (WriterT w m) 
MonadBase b m => MonadBase b (StateT s m) 
MonadBase b m => MonadBase b (StateT s m) 
MonadBase b m => MonadBase b (ReaderT r m) 
MonadBase b m => MonadBase b (ExceptT e m) 
(Error e, MonadBase b m) => MonadBase b (ErrorT e m) 
MonadBase b m => MonadBase b (ContT r m) 
MonadBase b m => MonadBase b (StateRefT ref s m) 
MonadBase b m => MonadBase b (WriterRefT ref w m) 
(Monoid w, MonadBase b m) => MonadBase b (RWST r w s m) 
(Monoid w, MonadBase b m) => MonadBase b (RWST r w s m) 
MonadBase b m => MonadBase b (RWSRefT refw refs r w s m) 
MonadBase ((->) r) ((->) r) 
MonadBase (Either e) (Either e) 
MonadBase (ST s) (ST s) 
MonadBase (ST s) (ST s) 

class MonadTrans t => MonadTransControl t where

Associated Types

type StT t a :: *

Monadic state of t.

Methods

liftWith :: Monad m => (Run t -> m a) -> t m a

liftWith is similar to lift in that it lifts a computation from the argument monad to the constructed monad.

Instances should satisfy similar laws as the MonadTrans laws:

liftWith . const . return = return
liftWith (const (m >>= f)) = liftWith (const m) >>= liftWith . const . f

The difference with lift is that before lifting the m computation liftWith captures the state of t. It then provides the m computation with a Run function that allows running t n computations in n (for all n) on the captured state.

restoreT :: Monad m => m (StT t a) -> t m a

Construct a t computation from the monadic state of t that is returned from a Run function.

Instances should satisfy:

liftWith (\run -> run t) >>= restoreT . return = t

class MonadBase b m => MonadBaseControl b m | m -> b where

Associated Types

type StM m a :: *

Monadic state of m.

Methods

liftBaseWith :: (RunInBase m b -> b a) -> m a

liftBaseWith is similar to liftIO and liftBase in that it lifts a base computation to the constructed monad.

Instances should satisfy similar laws as the MonadIO and MonadBase laws:

liftBaseWith . const . return = return
liftBaseWith (const (m >>= f)) = liftBaseWith (const m) >>= liftBaseWith . const . f

The difference with liftBase is that before lifting the base computation liftBaseWith captures the state of m. It then provides the base computation with a RunInBase function that allows running m computations in the base monad on the captured state.

restoreM :: StM m a -> m a

Construct a m computation from the monadic state of m that is returned from a RunInBase function.

Instances should satisfy:

liftBaseWith (\runInBase -> runInBase m) >>= restoreM = m