Control.Monad.Unlift
- Package
- purescript-unlift
- Repository
- tweag/purescript-unlift
#MonadUnlift Source
class MonadUnlift :: (Type -> Type) -> (Type -> Type) -> Constraint
class (MonadBase b m) <= MonadUnlift b m | m -> b where
Monads which allow their actions to be run in a base monad.
MonadUnlift
captures the opposite notion of MonadBase
- while
MonadBase
allows any base monad b
to be lifted into a transformed monad
m
, MonadUnlift
allows m
to be run in b
, as long as the outer
context is in m
.
Note that the laws given below require that a monad have no "monadic
state", which essentially limits instances to ReaderT
and IdentityT
stacks.
Instances should satisfy the following laws, which state that
unlift
is a transformer of monads for any given u
returned by
askUnlift
:
unlift u <<< pure = pure
unlift u (f =<< m) = unlift u <<< f =<< unlift u m
Members
withRunInBase :: forall x. ((m ~> b) -> b x) -> m x
Instances
MonadUnlift Array Array
MonadUnlift List List
MonadUnlift Maybe Maybe
MonadUnlift Effect Effect
MonadUnlift Aff Aff
MonadUnlift Identity Identity
MonadUnlift (Either e) (Either e)
(Monoid a) => MonadUnlift (Tuple a) (Tuple a)
(MonadUnlift b m) => MonadUnlift b (ReaderT r m)
#askUnlift Source
askUnlift :: forall b m. MonadUnlift b m => m (Unlift b m)
Returns a natural transformation from m
to b
within an m
context.
This can subsequently be used to run m
actions in the base monad b
.
#askRunInBase Source
askRunInBase :: forall b m a. MonadUnlift b m => m (m a -> b a)
A monomorphic version of askUnlift which can be more convenient when you only want to use the resulting runner function once with a concrete type.
If you run into type issues using this, try using askUnlit
instead.
#withUnlift Source
withUnlift :: forall b m a. MonadUnlift b m => (Unlift b m -> b a) -> m a
A version of withRunInBase
that provides an Unlift
wrapper instead of
a rank-2 polymorphic function.
#toBase Source
toBase :: forall b m a. MonadUnlift b m => m a -> m (b a)
Run the given action inside the base monad b
.
Run a base monad action with access to a runner function that is capable of running a monadic action
m
inb
(strictly speaking, a natural transformation fromm
tob
).