| Copyright | (c) 2021 Kowainik (c) 2017 FP Complete | 
|---|---|
| License | MPL-2.0 | 
| Maintainer | Kowainik <xrom.xkov@gmail.com> | 
| Stability | Stable | 
| Portability | Portable | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Unlift
Description
This module provides MonadUnlift typeclass and functions to work with it.
See MonadUnlift documentation for more information about its purpose.
Since: 0.0.0.0
Synopsis
- class MonadBase b m => MonadUnlift b m where- withRunInBase :: ((forall a. m a -> b a) -> b x) -> m x
 
- defaultWithRunInBase :: MonadUnlift b n => (n x -> m x) -> (forall a. m a -> n a) -> ((forall a. m a -> b a) -> b x) -> m x
- askRunInBase :: MonadUnlift b m => m (m a -> b a)
- newtype Unlift b m = Unlift {- runUnlift :: forall x. m x -> b x
 
- askUnlift :: MonadUnlift b m => m (Unlift b m)
Documentation
class MonadBase b m => MonadUnlift b m where Source #
Typeclass to allow actions in monadic context m to be run in the base monad b.
This typeclass is similar to MonadUnliftIO from the
unliftio package. However
MonadUnlift works with any base monad, not only IO.
This typeclass is helpful when writing code that is polymorphic over the base monad, so later you can select a different base monad for each specific use-case.
While you can use lift to allow some action to be lifted into another
monad, this class captures the opposite concept.
Instances of this typeclass should satisfy the following laws:
- Distributivity: - withRunInBase(\run -> run f >> run g) ≡- withRunInBase(\run -> run f) >>- withRunInBase(\run -> run g)
- Identity: - askUnlift>>= \u -> (- liftBase.- runUnliftu) m ≡ m
Since: 0.0.0.0
Methods
withRunInBase :: ((forall a. m a -> b a) -> b x) -> m x Source #
Convenient function to capture the monadic context m and run the b
    action with a runner function. The runner function is used to run a monadic
    action m in the base monad b.
Since: 0.0.0.0
Instances
| MonadUnlift IO IO Source # | Since: 0.0.0.0 | 
| MonadUnlift STM STM Source # | Since: 0.0.0.0 | 
| MonadUnlift b m => MonadUnlift b (ReaderT r m) Source # | Since: 0.0.0.0 | 
| MonadUnlift b m => MonadUnlift b (IdentityT m) Source # | Since: 0.0.0.0 | 
| MonadUnlift (ST s) (ST s) Source # | Since: 0.0.0.0 | 
Arguments
| :: MonadUnlift b n | |
| => (n x -> m x) | Wrapper | 
| -> (forall a. m a -> n a) | Unwrapper | 
| -> ((forall a. m a -> b a) -> b x) | Action to do in base monad | 
| -> m x | Result in unlifted monad | 
A helper function for implementing MonadUnlift instances.
Useful for the common case where you want to simply delegate to the
underlying transformer in newtypes.
Example:
newtype AppT m a = AppT
    { unAppT :: ReaderT Int m a
    } deriving newtype (Functor, Applicative, Monad)
instance (MonadUnlift b m) => MonadUnlift b (AppT m)
  where
    withRunInBase = defaultWithRunInBase AppT unAppT
Since: 0.0.0.0
askRunInBase :: MonadUnlift b m => m (m a -> b a) Source #
Capture the current monadic context m, providing the ability to
run monadic actions in the base monad b.
Useful when you need to apply on one concrete type.
Note: If you run into issues when using this function, most likely that
you need askUnlift instead.
Since: 0.0.0.0
Polymorphic wrapper over the function returned by withRunInBase.
Use askUnlift instead of askRunInBase when you need to use the return
unlift with variables of different types.
Since: 0.0.0.0
askUnlift :: MonadUnlift b m => m (Unlift b m) Source #
Similar to askRunInBase, but works with the Unlift wrapper.
Use askUnlift instead of askRunInBase when you need to use the return
unlift with variables of different types.
Since: 0.0.0.0