{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE UndecidableInstances #-}
module Effectful.Dispatch.Dynamic
(
send
, EffectHandler
, interpret
, reinterpret
, interpose
, impose
, LocalEnv
, localSeqUnlift
, localSeqUnliftIO
, localUnlift
, localUnliftIO
, localSeqLift
, localLift
, withLiftMap
, withLiftMapIO
, localLiftUnlift
, localLiftUnliftIO
, SharedSuffix
, HasCallStack
) where
import Control.Monad.IO.Unlift
import GHC.Stack (HasCallStack)
import GHC.TypeLits
import Effectful.Internal.Effect
import Effectful.Internal.Env
import Effectful.Internal.Monad
import Effectful.Internal.Utils
interpret
:: DispatchOf e ~ Dynamic
=> EffectHandler e es
-> Eff (e : es) a
-> Eff es a
interpret :: forall (e :: Effect) (es :: [Effect]) a.
(DispatchOf e ~ 'Dynamic) =>
EffectHandler e es -> Eff (e : es) a -> Eff es a
interpret EffectHandler e es
handler Eff (e : es) a
m = forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ forall (e :: Effect) (es :: [Effect]) a.
(DispatchOf e ~ 'Dynamic) =>
Handler e -> Eff (e : es) a -> Eff es a
runHandler (Env es -> Handler e
mkHandler Env es
es) Eff (e : es) a
m
where
mkHandler :: Env es -> Handler e
mkHandler Env es
es = forall (handlerEs :: [Effect]) (e :: Effect).
Env handlerEs -> EffectHandler e handlerEs -> Handler e
Handler Env es
es (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
?callStack in EffectHandler e es
handler)
reinterpret
:: DispatchOf e ~ Dynamic
=> (Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs
-> Eff (e : es) a
-> Eff es b
reinterpret :: forall (e :: Effect) (handlerEs :: [Effect]) a (es :: [Effect]) b.
(DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff (e : es) a -> Eff es b
reinterpret Eff handlerEs a -> Eff es b
runHandlerEs EffectHandler e handlerEs
handler Eff (e : es) a
m = forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff handlerEs a -> Eff es b
runHandlerEs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env handlerEs
handlerEs -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ forall (e :: Effect) (es :: [Effect]) a.
(DispatchOf e ~ 'Dynamic) =>
Handler e -> Eff (e : es) a -> Eff es a
runHandler (Env handlerEs -> Handler e
mkHandler Env handlerEs
handlerEs) Eff (e : es) a
m
where
mkHandler :: Env handlerEs -> Handler e
mkHandler Env handlerEs
es = forall (handlerEs :: [Effect]) (e :: Effect).
Env handlerEs -> EffectHandler e handlerEs -> Handler e
Handler Env handlerEs
es (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
?callStack in EffectHandler e handlerEs
handler)
interpose
:: forall e es a. (DispatchOf e ~ Dynamic, e :> es)
=> EffectHandler e es
-> Eff es a
-> Eff es a
interpose :: forall (e :: Effect) (es :: [Effect]) a.
(DispatchOf e ~ 'Dynamic, e :> es) =>
EffectHandler e es -> Eff es a -> Eff es a
interpose EffectHandler e es
handler Eff es a
m = forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
inlineBracket
(do
Handler e
origHandler <- forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv @e Env es
es
forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
EffectRep (DispatchOf e) e
-> Relinker (EffectRep (DispatchOf e)) e -> Env es -> IO (Env es)
replaceEnv Handler e
origHandler forall (e :: Effect). Relinker Handler e
relinkHandler Env es
es
)
(\Env es
newEs -> do
forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
Env es -> EffectRep (DispatchOf e) e -> IO ()
putEnv Env es
es forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv @e Env es
newEs
forall (e :: Effect) (es :: [Effect]). (e :> es) => Env es -> IO ()
unreplaceEnv @e Env es
newEs
)
(\Env es
newEs -> do
forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
Env es -> EffectRep (DispatchOf e) e -> IO ()
putEnv Env es
es forall a b. (a -> b) -> a -> b
$ Env es -> Handler e
mkHandler Env es
newEs
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff Eff es a
m Env es
es
)
where
mkHandler :: Env es -> Handler e
mkHandler Env es
es = forall (handlerEs :: [Effect]) (e :: Effect).
Env handlerEs -> EffectHandler e handlerEs -> Handler e
Handler Env es
es (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
?callStack in EffectHandler e es
handler)
impose
:: forall e es handlerEs a b. (DispatchOf e ~ Dynamic, e :> es)
=> (Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs
-> Eff es a
-> Eff es b
impose :: forall (e :: Effect) (es :: [Effect]) (handlerEs :: [Effect]) a b.
(DispatchOf e ~ 'Dynamic, e :> es) =>
(Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff es a -> Eff es b
impose Eff handlerEs a -> Eff es b
runHandlerEs EffectHandler e handlerEs
handler Eff es a
m = forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
inlineBracket
(do
Handler e
origHandler <- forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv @e Env es
es
forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
EffectRep (DispatchOf e) e
-> Relinker (EffectRep (DispatchOf e)) e -> Env es -> IO (Env es)
replaceEnv Handler e
origHandler forall (e :: Effect). Relinker Handler e
relinkHandler Env es
es
)
(\Env es
newEs -> do
forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
Env es -> EffectRep (DispatchOf e) e -> IO ()
putEnv Env es
es forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv @e Env es
newEs
forall (e :: Effect) (es :: [Effect]). (e :> es) => Env es -> IO ()
unreplaceEnv @e Env es
newEs
)
(\Env es
newEs -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
newEs) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff handlerEs a -> Eff es b
runHandlerEs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env handlerEs
handlerEs -> do
forall (e :: Effect) (es :: [Effect]).
(e :> es) =>
Env es -> EffectRep (DispatchOf e) e -> IO ()
putEnv Env es
es forall a b. (a -> b) -> a -> b
$ Env handlerEs -> Handler e
mkHandler Env handlerEs
handlerEs
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff Eff es a
m Env es
es
)
where
mkHandler :: Env handlerEs -> Handler e
mkHandler Env handlerEs
es = forall (handlerEs :: [Effect]) (e :: Effect).
Env handlerEs -> EffectHandler e handlerEs -> Handler e
Handler Env handlerEs
es (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
?callStack in EffectHandler e handlerEs
handler)
localSeqUnlift
:: (HasCallStack, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> ((forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> Eff es a
localSeqUnlift :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) a.
(HasCallStack, SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> ((forall r. Eff localEs r -> Eff es r) -> Eff es a) -> Eff es a
localSeqUnlift (LocalEnv Env localEs
les) (forall r. Eff localEs r -> Eff es r) -> Eff es a
k = forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
les forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall r. Eff localEs r -> Eff es r) -> Eff es a
k forall a b. (a -> b) -> a -> b
$ forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff localEs r -> IO r
unlift
localSeqUnliftIO
:: (HasCallStack, SharedSuffix es handlerEs, IOE :> es)
=> LocalEnv localEs handlerEs
-> ((forall r. Eff localEs r -> IO r) -> IO a)
-> Eff es a
localSeqUnliftIO :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) a.
(HasCallStack, SharedSuffix es handlerEs, IOE :> es) =>
LocalEnv localEs handlerEs
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> Eff es a
localSeqUnliftIO (LocalEnv Env localEs
les) (forall r. Eff localEs r -> IO r) -> IO a
k = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
les (forall r. Eff localEs r -> IO r) -> IO a
k
localUnlift
:: (HasCallStack, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> Eff es a
localUnlift :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) a.
(HasCallStack, SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> Eff es a
localUnlift (LocalEnv Env localEs
les) UnliftStrategy
strategy (forall r. Eff localEs r -> Eff es r) -> Eff es a
k = case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
les forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall r. Eff localEs r -> Eff es r) -> Eff es a
k forall a b. (a -> b) -> a -> b
$ forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff localEs r -> IO r
unlift
ConcUnlift Persistence
p Limit
l -> forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
concUnliftIO Env localEs
les Persistence
p Limit
l forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall r. Eff localEs r -> Eff es r) -> Eff es a
k forall a b. (a -> b) -> a -> b
$ forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff localEs r -> IO r
unlift
localUnliftIO
:: (HasCallStack, SharedSuffix es handlerEs, IOE :> es)
=> LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff localEs r -> IO r) -> IO a)
-> Eff es a
localUnliftIO :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) a.
(HasCallStack, SharedSuffix es handlerEs, IOE :> es) =>
LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff localEs r -> IO r) -> IO a)
-> Eff es a
localUnliftIO (LocalEnv Env localEs
les) UnliftStrategy
strategy (forall r. Eff localEs r -> IO r) -> IO a
k = case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
les (forall r. Eff localEs r -> IO r) -> IO a
k
ConcUnlift Persistence
p Limit
l -> forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (es :: [Effect]) a.
HasCallStack =>
Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
concUnliftIO Env localEs
les Persistence
p Limit
l (forall r. Eff localEs r -> IO r) -> IO a
k
localSeqLift
:: (HasCallStack, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> ((forall r. Eff es r -> Eff localEs r) -> Eff es a)
-> Eff es a
localSeqLift :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) a.
(HasCallStack, SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> ((forall r. Eff es r -> Eff localEs r) -> Eff es a) -> Eff es a
localSeqLift !LocalEnv localEs handlerEs
_ (forall r. Eff es r -> Eff localEs r) -> Eff es a
k = forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env es
es forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r) -> Eff es a
k forall a b. (a -> b) -> a -> b
$ forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff es r -> IO r
unlift
localLift
:: (HasCallStack, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff es r -> Eff localEs r) -> Eff es a)
-> Eff es a
localLift :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) a.
(HasCallStack, SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff es r -> Eff localEs r) -> Eff es a)
-> Eff es a
localLift !LocalEnv localEs handlerEs
_ UnliftStrategy
strategy (forall r. Eff es r -> Eff localEs r) -> Eff es a
k = case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env es
es forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r) -> Eff es a
k forall a b. (a -> b) -> a -> b
$ forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff es r -> IO r
unlift
ConcUnlift Persistence
p Limit
l -> forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
concUnliftIO Env es
es Persistence
p Limit
l forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r) -> Eff es a
k forall a b. (a -> b) -> a -> b
$ forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff es r -> IO r
unlift
withLiftMap
:: (HasCallStack, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> ((forall a b. (Eff es a -> Eff es b) -> Eff localEs a -> Eff localEs b) -> Eff es r)
-> Eff es r
withLiftMap :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) r.
(HasCallStack, SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> ((forall a b.
(Eff es a -> Eff es b) -> Eff localEs a -> Eff localEs b)
-> Eff es r)
-> Eff es r
withLiftMap !LocalEnv localEs handlerEs
_ (forall a b.
(Eff es a -> Eff es b) -> Eff localEs a -> Eff localEs b)
-> Eff es r
k = forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall a b.
(Eff es a -> Eff es b) -> Eff localEs a -> Eff localEs b)
-> Eff es r
k forall a b. (a -> b) -> a -> b
$ \Eff es a -> Eff es b
mapEff Eff localEs a
m -> forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env localEs
localEs -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
localEs forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es a -> Eff es b
mapEff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall a b. (a -> b) -> a -> b
$ forall r. Eff localEs r -> IO r
unlift Eff localEs a
m
withLiftMapIO
:: (HasCallStack, SharedSuffix es handlerEs, IOE :> es)
=> LocalEnv localEs handlerEs
-> ((forall a b. (IO a -> IO b) -> Eff localEs a -> Eff localEs b) -> Eff es r)
-> Eff es r
withLiftMapIO :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) r.
(HasCallStack, SharedSuffix es handlerEs, IOE :> es) =>
LocalEnv localEs handlerEs
-> ((forall a b. (IO a -> IO b) -> Eff localEs a -> Eff localEs b)
-> Eff es r)
-> Eff es r
withLiftMapIO !LocalEnv localEs handlerEs
_ (forall a b. (IO a -> IO b) -> Eff localEs a -> Eff localEs b)
-> Eff es r
k = (forall a b. (IO a -> IO b) -> Eff localEs a -> Eff localEs b)
-> Eff es r
k forall a b. (a -> b) -> a -> b
$ \IO a -> IO b
mapIO Eff localEs a
m -> forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env localEs
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
es forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> IO a -> IO b
mapIO forall a b. (a -> b) -> a -> b
$ forall r. Eff localEs r -> IO r
unlift Eff localEs a
m
localLiftUnlift
:: (HasCallStack, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff es r -> Eff localEs r) -> (forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> Eff es a
localLiftUnlift :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) a.
(HasCallStack, SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff es r -> Eff localEs r)
-> (forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> Eff es a
localLiftUnlift (LocalEnv Env localEs
les) UnliftStrategy
strategy (forall r. Eff es r -> Eff localEs r)
-> (forall r. Eff localEs r -> Eff es r) -> Eff es a
k = case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env es
es forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unliftEs -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
les forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unliftLocalEs -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r)
-> (forall r. Eff localEs r -> Eff es r) -> Eff es a
k (forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff es r -> IO r
unliftEs) (forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff localEs r -> IO r
unliftLocalEs)
ConcUnlift Persistence
p Limit
l -> forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
concUnliftIO Env es
es Persistence
p Limit
l forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unliftEs -> do
forall (es :: [Effect]) a.
HasCallStack =>
Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
concUnliftIO Env localEs
les Persistence
p Limit
l forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unliftLocalEs -> do
(forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r)
-> (forall r. Eff localEs r -> Eff es r) -> Eff es a
k (forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff es r -> IO r
unliftEs) (forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. Eff localEs r -> IO r
unliftLocalEs)
localLiftUnliftIO
:: (HasCallStack, SharedSuffix es handlerEs, IOE :> es)
=> LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. IO r -> Eff localEs r) -> (forall r. Eff localEs r -> IO r) -> IO a)
-> Eff es a
localLiftUnliftIO :: forall (es :: [Effect]) (handlerEs :: [Effect])
(localEs :: [Effect]) a.
(HasCallStack, SharedSuffix es handlerEs, IOE :> es) =>
LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. IO r -> Eff localEs r)
-> (forall r. Eff localEs r -> IO r) -> IO a)
-> Eff es a
localLiftUnliftIO (LocalEnv Env localEs
les) UnliftStrategy
strategy (forall r. IO r -> Eff localEs r)
-> (forall r. Eff localEs r -> IO r) -> IO a
k = case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
les forall a b. (a -> b) -> a -> b
$ (forall r. IO r -> Eff localEs r)
-> (forall r. Eff localEs r -> IO r) -> IO a
k forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_
ConcUnlift Persistence
p Limit
l -> forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (es :: [Effect]) a.
HasCallStack =>
Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
concUnliftIO Env localEs
les Persistence
p Limit
l forall a b. (a -> b) -> a -> b
$ (forall r. IO r -> Eff localEs r)
-> (forall r. Eff localEs r -> IO r) -> IO a
k forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_
class SharedSuffix (es1 :: [Effect]) (es2 :: [Effect])
instance {-# INCOHERENT #-} SharedSuffix es es
instance {-# INCOHERENT #-} SharedSuffix es1 es2 => SharedSuffix (e : es1) es2
instance {-# INCOHERENT #-} SharedSuffix es1 es2 => SharedSuffix es1 (e : es2)
instance
TypeError
( Text "Running local actions in monomorphic effect stacks is not supported." :$$:
Text "As a solution simply change the stack to have a polymorphic suffix."
) => SharedSuffix '[] '[]