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

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 Fieldsunlift :: 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 FieldsunliftBase :: 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:

• lift . return = return
• lift (m >>= f) = lift m >>= (lift . f)

Minimal complete definition

lift

Methods

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

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

Instances

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

Minimal complete definition

liftBase

Methods

liftBase :: b α -> m α #

Lift a computation from the base monad

Instances

class MonadTrans t => MonadTransControl t where #

Minimal complete definition

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

Instances

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

Minimal complete definition

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

Instances