{-# LANGUAGE DerivingVia #-}
module Control.Effect.Unlift
(
Unlift(..)
, unlift
, MonadBaseControlPure
, unliftToFinal
, runUnlift
, threadUnliftViaClass
, powerAlgUnlift
, powerAlgUnliftFinal
, UnliftToFinalC
, UnliftC
) where
import Control.Effect
import Control.Effect.Carrier
import Control.Effect.Internal.Unlift
import Control.Effect.Type.Unlift
unlift :: Eff (Unlift b) m => ((forall x. m x -> b x) -> b a) -> m a
unlift main = send (Unlift main)
{-# INLINE unlift #-}
runUnlift :: Carrier m
=> UnliftC m a
-> m a
runUnlift = unUnliftC
{-# INLINE runUnlift #-}
data UnliftToFinalH
instance ( MonadBaseControlPure b m
, Carrier m
)
=> PrimHandler UnliftToFinalH (Unlift b) m where
effPrimHandler (Unlift main) = unliftBase main
{-# INLINEABLE effPrimHandler #-}
type UnliftToFinalC b = InterpretPrimC UnliftToFinalH (Unlift b)
unliftToFinal :: ( MonadBaseControlPure b m
, Carrier m
)
=> UnliftToFinalC b m a
-> m a
unliftToFinal = interpretPrimViaHandler
{-# INLINE unliftToFinal #-}
powerAlgUnlift :: forall m p a
. Algebra' p m a
-> Algebra' (Unlift m ': p) m a
powerAlgUnlift alg = powerAlg alg $ \case
Unlift main -> main id
{-# INLINE powerAlgUnlift #-}
powerAlgUnliftFinal :: forall b m p a
. MonadBaseControlPure b m
=> Algebra' p m a
-> Algebra' (Unlift b ': p) m a
powerAlgUnliftFinal alg = powerAlg alg $ \case
Unlift main -> unliftBase main
{-# INLINE powerAlgUnliftFinal #-}