{-# OPTIONS_HADDOCK not-home #-}
module Control.Effect.Type.Unlift
(
Unlift(..)
, threadUnliftViaClass
, MonadBaseControlPure
, unliftBase
, MonadTransControlPure
, unliftT
) where
import Control.Effect.Internal.Union
import Control.Monad.Trans.Control
import Control.Monad.Trans.Reader
class a ~ StM m a => Pure m a
instance a ~ StM m a => Pure m a
class ( MonadBaseControl b m
, forall x. Pure m x
)
=> MonadBaseControlPure b m
instance ( MonadBaseControl b m
, forall x. Pure m x
)
=> MonadBaseControlPure b m
class a ~ StT t a => PureT t a
instance a ~ StT t a => PureT t a
class ( MonadTransControl t
, forall x. PureT t x
)
=> MonadTransControlPure t
instance ( MonadTransControl t
, forall x. PureT t x
)
=> MonadTransControlPure t
unliftBase :: forall b m a
. MonadBaseControlPure b m
=> ((forall x. m x -> b x) -> b a)
-> m a
unliftBase main = liftBaseWith $ \lower ->
main (lower :: Pure m x => m x -> b x)
{-# INLINE unliftBase #-}
unliftT :: forall t m a
. (MonadTransControlPure t, Monad m)
=> ((forall n x. Monad n => t n x -> n x) -> m a)
-> t m a
unliftT main = liftWith $ \lower ->
main (lower :: (PureT t x, Monad n) => t n x -> n x)
{-# INLINE unliftT #-}
data Unlift b m a where
Unlift :: forall b m a. ((forall x. m x -> b x) -> b a) -> Unlift b m a
threadUnliftViaClass :: forall b t m a
. (MonadTransControlPure t, Monad m)
=> (forall x. Unlift b m x -> m x)
-> Unlift b (t m) a -> t m a
threadUnliftViaClass alg (Unlift main) = unliftT $ \lowerT ->
alg $ Unlift $ \lowerM -> main (lowerM . lowerT)
{-# INLINE threadUnliftViaClass #-}
instance ThreadsEff (ReaderT i) (Unlift b) where
threadEff alg (Unlift main) = ReaderT $ \s ->
alg $ Unlift $ \lower -> main (lower . (`runReaderT` s))
{-# INLINE threadEff #-}