{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE UndecidableInstances #-}
module Effectful.Dispatch.Dynamic
(
send
, passthrough
, EffectHandler
, interpret
, interpretWith
, reinterpret
, reinterpretWith
, interpose
, interposeWith
, impose
, imposeWith
, LocalEnv
, localSeqUnlift
, localSeqUnliftIO
, localUnlift
, localUnliftIO
, localSeqLift
, localLift
, withLiftMap
, withLiftMapIO
, localLiftUnlift
, localLiftUnliftIO
, localSeqLend
, localLend
, localSeqBorrow
, localBorrow
, SharedSuffix
, KnownSubset
, EffectHandler_
, interpret_
, interpretWith_
, reinterpret_
, reinterpretWith_
, interpose_
, interposeWith_
, impose_
, imposeWith_
, HasCallStack
) where
import Control.Monad
import Data.Primitive.PrimArray
import GHC.Stack
import GHC.TypeLits
import Effectful.Internal.Effect
import Effectful.Internal.Env
import Effectful.Internal.Monad
import Effectful.Internal.Utils
passthrough
:: (HasCallStack, DispatchOf e ~ Dynamic, e :> es, e :> localEs, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> e (Eff localEs) a
-> Eff es a
passthrough :: forall (e :: Effect) (es :: [Effect]) (localEs :: [Effect])
(handlerEs :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es, e :> localEs,
SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff es a
passthrough (LocalEnv Env localEs
les) e (Eff localEs) a
op = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Handler Env handlerEs
handlerEs (HandlerImpl EffectHandler e handlerEs
handler) <- Env es -> IO (EffectRep (DispatchOf e) e)
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv Env es
es
Bool -> IO () -> IO ()
forall (f :: Type -> Type). Applicative f => Bool -> f () -> f ()
when (Env localEs -> IORef' Storage
forall (es :: [Effect]). Env es -> IORef' Storage
envStorage Env localEs
les IORef' Storage -> IORef' Storage -> Bool
forall a. Eq a => a -> a -> Bool
/= Env handlerEs -> IORef' Storage
forall (es :: [Effect]). Env es -> IORef' Storage
envStorage Env handlerEs
handlerEs) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
[Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"les and handlerEs point to different Storages"
Eff handlerEs a -> Env handlerEs -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff ((HasCallStack =>
LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a)
-> LocalEnv localEs handlerEs
-> e (Eff localEs) a
-> Eff handlerEs a
forall a. HasCallStack => (HasCallStack => a) -> a
withFrozenCallStack HasCallStack =>
LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a
LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a
EffectHandler e handlerEs
handler (Env localEs -> LocalEnv localEs handlerEs
forall (localEs :: [Effect]) (handlerEs :: [Effect]).
Env localEs -> LocalEnv localEs handlerEs
LocalEnv Env localEs
les) e (Eff localEs) a
op) Env handlerEs
handlerEs
{-# NOINLINE passthrough #-}
interpret
:: (HasCallStack, DispatchOf e ~ Dynamic)
=> EffectHandler e es
-> Eff (e : es) a
-> Eff es a
interpret :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
EffectHandler e es -> Eff (e : es) a -> Eff es a
interpret EffectHandler e es
handler Eff (e : es) a
action = Eff (e : es) a -> HandlerImpl e es -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Eff (e : es) a -> HandlerImpl e es -> Eff es a
interpretImpl Eff (e : es) a
action (HandlerImpl e es -> Eff es a) -> HandlerImpl e es -> Eff es a
forall a b. (a -> b) -> a -> b
$
EffectHandler e es -> HandlerImpl e es
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
EffectHandler e es
handler)
interpretWith
:: (HasCallStack, DispatchOf e ~ Dynamic)
=> Eff (e : es) a
-> EffectHandler e es
-> Eff es a
interpretWith :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Eff (e : es) a -> EffectHandler e es -> Eff es a
interpretWith Eff (e : es) a
action EffectHandler e es
handler = Eff (e : es) a -> HandlerImpl e es -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Eff (e : es) a -> HandlerImpl e es -> Eff es a
interpretImpl Eff (e : es) a
action (HandlerImpl e es -> Eff es a) -> HandlerImpl e es -> Eff es a
forall a b. (a -> b) -> a -> b
$
EffectHandler e es -> HandlerImpl e es
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
EffectHandler e es
handler)
reinterpret
:: (HasCallStack, 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.
(HasCallStack, 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
runSetup EffectHandler e handlerEs
handler Eff (e : es) a
action = (Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
forall (e :: Effect) (handlerEs :: [Effect]) a (es :: [Effect]) b.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
reinterpretImpl Eff handlerEs a -> Eff es b
runSetup Eff (e : es) a
action (HandlerImpl e handlerEs -> Eff es b)
-> HandlerImpl e handlerEs -> Eff es b
forall a b. (a -> b) -> a -> b
$
EffectHandler e handlerEs -> HandlerImpl e handlerEs
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a
EffectHandler e handlerEs
handler)
reinterpretWith
:: (HasCallStack, DispatchOf e ~ Dynamic)
=> (Eff handlerEs a -> Eff es b)
-> Eff (e : es) a
-> EffectHandler e handlerEs
-> Eff es b
reinterpretWith :: forall (e :: Effect) (handlerEs :: [Effect]) a (es :: [Effect]) b.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> EffectHandler e handlerEs -> Eff es b
reinterpretWith Eff handlerEs a -> Eff es b
runSetup Eff (e : es) a
action EffectHandler e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
forall (e :: Effect) (handlerEs :: [Effect]) a (es :: [Effect]) b.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
reinterpretImpl Eff handlerEs a -> Eff es b
runSetup Eff (e : es) a
action (HandlerImpl e handlerEs -> Eff es b)
-> HandlerImpl e handlerEs -> Eff es b
forall a b. (a -> b) -> a -> b
$
EffectHandler e handlerEs -> HandlerImpl e handlerEs
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a
EffectHandler e handlerEs
handler)
interpose
:: (HasCallStack, DispatchOf e ~ Dynamic, e :> es)
=> EffectHandler e es
-> Eff es a
-> Eff es a
interpose :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
EffectHandler e es -> Eff es a -> Eff es a
interpose EffectHandler e es
handler Eff es a
action = Eff es a -> HandlerImpl e es -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
Eff es a -> HandlerImpl e es -> Eff es a
interposeImpl Eff es a
action (HandlerImpl e es -> Eff es a) -> HandlerImpl e es -> Eff es a
forall a b. (a -> b) -> a -> b
$
EffectHandler e es -> HandlerImpl e es
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
EffectHandler e es
handler)
interposeWith
:: (HasCallStack, DispatchOf e ~ Dynamic, e :> es)
=> Eff es a
-> EffectHandler e es
-> Eff es a
interposeWith :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
Eff es a -> EffectHandler e es -> Eff es a
interposeWith Eff es a
action EffectHandler e es
handler = Eff es a -> HandlerImpl e es -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
Eff es a -> HandlerImpl e es -> Eff es a
interposeImpl Eff es a
action (HandlerImpl e es -> Eff es a) -> HandlerImpl e es -> Eff es a
forall a b. (a -> b) -> a -> b
$
EffectHandler e es -> HandlerImpl e es
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
EffectHandler e es
handler)
impose
:: (HasCallStack, 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.
(HasCallStack, 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
runSetup EffectHandler e handlerEs
handler Eff es a
action = (Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
forall (e :: Effect) (es :: [Effect]) (handlerEs :: [Effect]) a b.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
(Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
imposeImpl Eff handlerEs a -> Eff es b
runSetup Eff es a
action (HandlerImpl e handlerEs -> Eff es b)
-> HandlerImpl e handlerEs -> Eff es b
forall a b. (a -> b) -> a -> b
$
EffectHandler e handlerEs -> HandlerImpl e handlerEs
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a
EffectHandler e handlerEs
handler)
imposeWith
:: (HasCallStack, DispatchOf e ~ Dynamic, e :> es)
=> (Eff handlerEs a -> Eff es b)
-> Eff es a
-> EffectHandler e handlerEs
-> Eff es b
imposeWith :: forall (e :: Effect) (es :: [Effect]) (handlerEs :: [Effect]) a b.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
(Eff handlerEs a -> Eff es b)
-> Eff es a -> EffectHandler e handlerEs -> Eff es b
imposeWith Eff handlerEs a -> Eff es b
runSetup Eff es a
action EffectHandler e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
forall (e :: Effect) (es :: [Effect]) (handlerEs :: [Effect]) a b.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
(Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
imposeImpl Eff handlerEs a -> Eff es b
runSetup Eff es a
action (HandlerImpl e handlerEs -> Eff es b)
-> HandlerImpl e handlerEs -> Eff es b
forall a b. (a -> b) -> a -> b
$
EffectHandler e handlerEs -> HandlerImpl e handlerEs
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a
EffectHandler e handlerEs
handler)
type EffectHandler_ (e :: Effect) (es :: [Effect])
= forall a localEs. HasCallStack
=> e (Eff localEs) a
-> Eff es a
interpret_
:: (HasCallStack, DispatchOf e ~ Dynamic)
=> EffectHandler_ e es
-> Eff (e : es) a
-> Eff es a
interpret_ :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
EffectHandler_ e es -> Eff (e : es) a -> Eff es a
interpret_ EffectHandler_ e es
handler Eff (e : es) a
action = Eff (e : es) a -> HandlerImpl e es -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Eff (e : es) a -> HandlerImpl e es -> Eff es a
interpretImpl Eff (e : es) a
action (HandlerImpl e es -> Eff es a) -> HandlerImpl e es -> Eff es a
forall a b. (a -> b) -> a -> b
$
EffectHandler e es -> HandlerImpl e es
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in (e (Eff localEs) a -> Eff es a)
-> LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
forall a b. a -> b -> a
const e (Eff localEs) a -> Eff es a
EffectHandler_ e es
handler)
interpretWith_
:: (HasCallStack, DispatchOf e ~ Dynamic)
=> Eff (e : es) a
-> EffectHandler_ e es
-> Eff es a
interpretWith_ :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Eff (e : es) a -> EffectHandler_ e es -> Eff es a
interpretWith_ Eff (e : es) a
action EffectHandler_ e es
handler = Eff (e : es) a -> HandlerImpl e es -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Eff (e : es) a -> HandlerImpl e es -> Eff es a
interpretImpl Eff (e : es) a
action (HandlerImpl e es -> Eff es a) -> HandlerImpl e es -> Eff es a
forall a b. (a -> b) -> a -> b
$
EffectHandler e es -> HandlerImpl e es
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in (e (Eff localEs) a -> Eff es a)
-> LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
forall a b. a -> b -> a
const e (Eff localEs) a -> Eff es a
EffectHandler_ e es
handler)
reinterpret_
:: (HasCallStack, 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.
(HasCallStack, 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
runSetup EffectHandler_ e handlerEs
handler Eff (e : es) a
action = (Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
forall (e :: Effect) (handlerEs :: [Effect]) a (es :: [Effect]) b.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
reinterpretImpl Eff handlerEs a -> Eff es b
runSetup Eff (e : es) a
action (HandlerImpl e handlerEs -> Eff es b)
-> HandlerImpl e handlerEs -> Eff es b
forall a b. (a -> b) -> a -> b
$
EffectHandler e handlerEs -> HandlerImpl e handlerEs
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in (e (Eff localEs) a -> Eff handlerEs a)
-> LocalEnv localEs handlerEs
-> e (Eff localEs) a
-> Eff handlerEs a
forall a b. a -> b -> a
const e (Eff localEs) a -> Eff handlerEs a
EffectHandler_ e handlerEs
handler)
reinterpretWith_
:: (HasCallStack, DispatchOf e ~ Dynamic)
=> (Eff handlerEs a -> Eff es b)
-> Eff (e : es) a
-> EffectHandler_ e handlerEs
-> Eff es b
reinterpretWith_ :: forall (e :: Effect) (handlerEs :: [Effect]) a (es :: [Effect]) b.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> EffectHandler_ e handlerEs -> Eff es b
reinterpretWith_ Eff handlerEs a -> Eff es b
runSetup Eff (e : es) a
action EffectHandler_ e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
forall (e :: Effect) (handlerEs :: [Effect]) a (es :: [Effect]) b.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
reinterpretImpl Eff handlerEs a -> Eff es b
runSetup Eff (e : es) a
action (HandlerImpl e handlerEs -> Eff es b)
-> HandlerImpl e handlerEs -> Eff es b
forall a b. (a -> b) -> a -> b
$
EffectHandler e handlerEs -> HandlerImpl e handlerEs
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in (e (Eff localEs) a -> Eff handlerEs a)
-> LocalEnv localEs handlerEs
-> e (Eff localEs) a
-> Eff handlerEs a
forall a b. a -> b -> a
const e (Eff localEs) a -> Eff handlerEs a
EffectHandler_ e handlerEs
handler)
interpose_
:: (HasCallStack, DispatchOf e ~ Dynamic, e :> es)
=> EffectHandler_ e es
-> Eff es a
-> Eff es a
interpose_ :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
EffectHandler_ e es -> Eff es a -> Eff es a
interpose_ EffectHandler_ e es
handler Eff es a
action = Eff es a -> HandlerImpl e es -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
Eff es a -> HandlerImpl e es -> Eff es a
interposeImpl Eff es a
action (HandlerImpl e es -> Eff es a) -> HandlerImpl e es -> Eff es a
forall a b. (a -> b) -> a -> b
$
EffectHandler e es -> HandlerImpl e es
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in (e (Eff localEs) a -> Eff es a)
-> LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
forall a b. a -> b -> a
const e (Eff localEs) a -> Eff es a
EffectHandler_ e es
handler)
interposeWith_
:: (HasCallStack, DispatchOf e ~ Dynamic, e :> es)
=> Eff es a
-> EffectHandler_ e es
-> Eff es a
interposeWith_ :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
Eff es a -> EffectHandler_ e es -> Eff es a
interposeWith_ Eff es a
action EffectHandler_ e es
handler = Eff es a -> HandlerImpl e es -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
Eff es a -> HandlerImpl e es -> Eff es a
interposeImpl Eff es a
action (HandlerImpl e es -> Eff es a) -> HandlerImpl e es -> Eff es a
forall a b. (a -> b) -> a -> b
$
EffectHandler e es -> HandlerImpl e es
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in (e (Eff localEs) a -> Eff es a)
-> LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
forall a b. a -> b -> a
const e (Eff localEs) a -> Eff es a
EffectHandler_ e es
handler)
impose_
:: (HasCallStack, 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.
(HasCallStack, 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
runSetup EffectHandler_ e handlerEs
handler Eff es a
action = (Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
forall (e :: Effect) (es :: [Effect]) (handlerEs :: [Effect]) a b.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
(Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
imposeImpl Eff handlerEs a -> Eff es b
runSetup Eff es a
action (HandlerImpl e handlerEs -> Eff es b)
-> HandlerImpl e handlerEs -> Eff es b
forall a b. (a -> b) -> a -> b
$
EffectHandler e handlerEs -> HandlerImpl e handlerEs
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in (e (Eff localEs) a -> Eff handlerEs a)
-> LocalEnv localEs handlerEs
-> e (Eff localEs) a
-> Eff handlerEs a
forall a b. a -> b -> a
const e (Eff localEs) a -> Eff handlerEs a
EffectHandler_ e handlerEs
handler)
imposeWith_
:: (HasCallStack, DispatchOf e ~ Dynamic, e :> es)
=> (Eff handlerEs a -> Eff es b)
-> Eff es a
-> EffectHandler_ e handlerEs
-> Eff es b
imposeWith_ :: forall (e :: Effect) (es :: [Effect]) (handlerEs :: [Effect]) a b.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
(Eff handlerEs a -> Eff es b)
-> Eff es a -> EffectHandler_ e handlerEs -> Eff es b
imposeWith_ Eff handlerEs a -> Eff es b
runSetup Eff es a
action EffectHandler_ e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
forall (e :: Effect) (es :: [Effect]) (handlerEs :: [Effect]) a b.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
(Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
imposeImpl Eff handlerEs a -> Eff es b
runSetup Eff es a
action (HandlerImpl e handlerEs -> Eff es b)
-> HandlerImpl e handlerEs -> Eff es b
forall a b. (a -> b) -> a -> b
$
EffectHandler e handlerEs -> HandlerImpl e handlerEs
forall (e :: Effect) (es :: [Effect]).
EffectHandler e es -> HandlerImpl e es
HandlerImpl (let ?callStack = CallStack -> CallStack
thawCallStack HasCallStack
CallStack
?callStack in (e (Eff localEs) a -> Eff handlerEs a)
-> LocalEnv localEs handlerEs
-> e (Eff localEs) a
-> Eff handlerEs a
forall a b. a -> b -> a
const e (Eff localEs) a -> Eff handlerEs a
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 = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
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) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff localEs r -> Eff es r) -> Eff es a
k ((forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> (forall r. Eff localEs r -> Eff es r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff localEs r -> IO r) -> Eff localEs r -> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff localEs r -> IO r
forall r. Eff localEs r -> IO r
unlift
{-# INLINE localSeqUnlift #-}
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 = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
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
{-# INLINE localSeqUnliftIO #-}
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 = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
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) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff localEs r -> Eff es r) -> Eff es a
k ((forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> (forall r. Eff localEs r -> Eff es r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff localEs r -> IO r) -> Eff localEs r -> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff localEs r -> IO r
forall r. Eff localEs r -> IO r
unlift
UnliftStrategy
SeqForkUnlift -> Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqForkUnliftIO Env localEs
les (((forall r. Eff localEs r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff localEs r -> Eff es r) -> Eff es a
k ((forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> (forall r. Eff localEs r -> Eff es r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff localEs r -> IO r) -> Eff localEs r -> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff localEs r -> IO r
forall r. Eff localEs r -> IO r
unlift
ConcUnlift Persistence
p Limit
l -> Env localEs
-> Persistence
-> Limit
-> ((forall r. Eff localEs r -> IO r) -> IO a)
-> IO a
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) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff localEs r -> Eff es r) -> Eff es a
k ((forall r. Eff localEs r -> Eff es r) -> Eff es a)
-> (forall r. Eff localEs r -> Eff es r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff localEs r -> IO r) -> Eff localEs r -> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff localEs r -> IO r
forall r. Eff localEs r -> IO r
unlift
{-# INLINE localUnlift #-}
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 = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
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
UnliftStrategy
SeqForkUnlift -> Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqForkUnliftIO Env localEs
les (forall r. Eff localEs r -> IO r) -> IO a
k
ConcUnlift Persistence
p Limit
l -> Env localEs
-> Persistence
-> Limit
-> ((forall r. Eff localEs r -> IO r) -> IO a)
-> IO a
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
{-# INLINE localUnliftIO #-}
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 Env localEs
les) (forall r. Eff es r -> Eff localEs r) -> Eff es a
k = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env es
es (((forall r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r) -> Eff es a
k ((forall r. Eff es r -> Eff localEs r) -> Eff es a)
-> (forall r. Eff es r -> Eff localEs r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff es r -> IO r) -> Eff es r -> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es r -> IO r
forall r. Eff es r -> IO r
unlift
{-# INLINE localSeqLift #-}
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 Env localEs
les) UnliftStrategy
strategy (forall r. Eff es r -> Eff localEs r) -> Eff es a
k = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env es
es (((forall r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r) -> Eff es a
k ((forall r. Eff es r -> Eff localEs r) -> Eff es a)
-> (forall r. Eff es r -> Eff localEs r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff es r -> IO r) -> Eff es r -> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es r -> IO r
forall r. Eff es r -> IO r
unlift
UnliftStrategy
SeqForkUnlift -> Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqForkUnliftIO Env es
es (((forall r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r) -> Eff es a
k ((forall r. Eff es r -> Eff localEs r) -> Eff es a)
-> (forall r. Eff es r -> Eff localEs r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff es r -> IO r) -> Eff es r -> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es r -> IO r
forall r. Eff es r -> IO r
unlift
ConcUnlift Persistence
p Limit
l -> Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
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 r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff es r -> Eff localEs r) -> Eff es a
k ((forall r. Eff es r -> Eff localEs r) -> Eff es a)
-> (forall r. Eff es r -> Eff localEs r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff es r -> IO r) -> Eff es r -> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es r -> IO r
forall r. Eff es r -> IO r
unlift
{-# INLINE localLift #-}
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 Env localEs
les) (forall a b.
(Eff es a -> Eff es b) -> Eff localEs a -> Eff localEs b)
-> Eff es r
k = (Env es -> IO r) -> Eff es r
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO r) -> Eff es r) -> (Env es -> IO r) -> Eff es r
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
(Eff es r -> Env es -> IO r
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es r -> IO r) -> Eff es r -> IO r
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.
(Eff es a -> Eff es b) -> Eff localEs a -> Eff localEs b)
-> Eff es r)
-> (forall a b.
(Eff es a -> Eff es b) -> Eff localEs a -> Eff localEs b)
-> Eff es r
forall a b. (a -> b) -> a -> b
$ \Eff es a -> Eff es b
mapEff Eff localEs a
m -> (Env localEs -> IO b) -> Eff localEs b
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env localEs -> IO b) -> Eff localEs b)
-> (Env localEs -> IO b) -> Eff localEs b
forall a b. (a -> b) -> a -> b
$ \Env localEs
localEs -> do
Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO b) -> IO b
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
localEs (((forall r. Eff localEs r -> IO r) -> IO b) -> IO b)
-> ((forall r. Eff localEs r -> IO r) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> do
(Eff es b -> Env es -> IO b
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es b -> IO b) -> (IO a -> Eff es b) -> IO a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es a -> Eff es b
mapEff (Eff es a -> Eff es b) -> (IO a -> Eff es a) -> IO a -> Eff es b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> Eff es a
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO a -> IO b) -> IO a -> IO b
forall a b. (a -> b) -> a -> b
$ Eff localEs a -> IO a
forall r. Eff localEs r -> IO r
unlift Eff localEs a
m
{-# INLINE withLiftMap #-}
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 Env localEs
les) (forall a b. (IO a -> IO b) -> Eff localEs a -> Eff localEs b)
-> Eff es r
k = (Env es -> IO r) -> Eff es r
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO r) -> Eff es r) -> (Env es -> IO r) -> Eff es r
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
(Eff es r -> Env es -> IO r
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es r -> IO r) -> Eff es r -> IO r
forall a b. (a -> b) -> a -> b
$ (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)
-> (forall a b. (IO a -> IO b) -> Eff localEs a -> Eff localEs b)
-> Eff es r
forall a b. (a -> b) -> a -> b
$ \IO a -> IO b
mapIO Eff localEs a
m -> (Env localEs -> IO b) -> Eff localEs b
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env localEs -> IO b) -> Eff localEs b)
-> (Env localEs -> IO b) -> Eff localEs b
forall a b. (a -> b) -> a -> b
$ \Env localEs
localEs -> do
Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO b) -> IO b
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env localEs
localEs (((forall r. Eff localEs r -> IO r) -> IO b) -> IO b)
-> ((forall r. Eff localEs r -> IO r) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unlift -> IO a -> IO b
mapIO (IO a -> IO b) -> IO a -> IO b
forall a b. (a -> b) -> a -> b
$ Eff localEs a -> IO a
forall r. Eff localEs r -> IO r
unlift Eff localEs a
m
{-# INLINE withLiftMapIO #-}
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 = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env es
es (((forall r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unliftEs -> do
Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
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) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unliftLocalEs -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
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 (IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff es r -> IO r) -> Eff es r -> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es r -> IO r
forall r. Eff es r -> IO r
unliftEs) (IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff localEs r -> IO r) -> Eff localEs r -> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff localEs r -> IO r
forall r. Eff localEs r -> IO r
unliftLocalEs)
UnliftStrategy
SeqForkUnlift -> Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqForkUnliftIO Env es
es (((forall r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unliftEs -> do
Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqForkUnliftIO Env localEs
les (((forall r. Eff localEs r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unliftLocalEs -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
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 (IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff es r -> IO r) -> Eff es r -> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es r -> IO r
forall r. Eff es r -> IO r
unliftEs) (IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff localEs r -> IO r) -> Eff localEs r -> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff localEs r -> IO r
forall r. Eff localEs r -> IO r
unliftLocalEs)
ConcUnlift Persistence
p Limit
l -> Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
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 r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unliftEs -> do
Env localEs
-> Persistence
-> Limit
-> ((forall r. Eff localEs r -> IO r) -> IO a)
-> IO a
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) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> IO r
unliftLocalEs -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
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 (IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff es r -> IO r) -> Eff es r -> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es r -> IO r
forall r. Eff es r -> IO r
unliftEs) (IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff localEs r -> IO r) -> Eff localEs r -> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff localEs r -> IO r
forall r. Eff localEs r -> IO r
unliftLocalEs)
{-# INLINE localLiftUnlift #-}
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 = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env es -> Env localEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es
es Env localEs
les
case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
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) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. IO r -> Eff localEs r)
-> (forall r. Eff localEs r -> IO r) -> IO a
k IO r -> Eff localEs r
forall r. IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_
UnliftStrategy
SeqForkUnlift -> Env localEs -> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqForkUnliftIO Env localEs
les (((forall r. Eff localEs r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. IO r -> Eff localEs r)
-> (forall r. Eff localEs r -> IO r) -> IO a
k IO r -> Eff localEs r
forall r. IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_
ConcUnlift Persistence
p Limit
l -> Env localEs
-> Persistence
-> Limit
-> ((forall r. Eff localEs r -> IO r) -> IO a)
-> IO a
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) -> IO a)
-> ((forall r. Eff localEs r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. IO r -> Eff localEs r)
-> (forall r. Eff localEs r -> IO r) -> IO a
k IO r -> Eff localEs r
forall r. IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_
{-# INLINE localLiftUnliftIO #-}
localSeqLend
:: forall lentEs es handlerEs localEs a
. (HasCallStack, KnownSubset lentEs es, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> ((forall r. Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a)
-> Eff es a
localSeqLend :: forall (lentEs :: [Effect]) (es :: [Effect])
(handlerEs :: [Effect]) (localEs :: [Effect]) a.
(HasCallStack, KnownSubset lentEs es, SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> ((forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a)
-> Eff es a
localSeqLend (LocalEnv Env localEs
les) (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a
k = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env (lentEs ++ localEs)
eles <- forall (es :: [Effect]) (srcEs :: [Effect]) (destEs :: [Effect]).
(HasCallStack, KnownSubset es srcEs) =>
Env srcEs -> Env destEs -> IO (Env (es ++ destEs))
copyRefs @lentEs Env es
es Env localEs
les
Env (lentEs ++ localEs)
-> ((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env (lentEs ++ localEs)
eles (((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff (lentEs ++ localEs) r -> IO r
unlift -> (Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a
k ((forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a)
-> (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff (lentEs ++ localEs) r -> IO r)
-> Eff (lentEs ++ localEs) r
-> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (lentEs ++ localEs) r -> IO r
forall r. Eff (lentEs ++ localEs) r -> IO r
unlift
{-# INLINE localSeqLend #-}
localLend
:: forall lentEs es handlerEs localEs a
. (HasCallStack, KnownSubset lentEs es, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a)
-> Eff es a
localLend :: forall (lentEs :: [Effect]) (es :: [Effect])
(handlerEs :: [Effect]) (localEs :: [Effect]) a.
(HasCallStack, KnownSubset lentEs es, SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a)
-> Eff es a
localLend (LocalEnv Env localEs
les) UnliftStrategy
strategy (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a
k = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env (lentEs ++ localEs)
eles <- forall (es :: [Effect]) (srcEs :: [Effect]) (destEs :: [Effect]).
(HasCallStack, KnownSubset es srcEs) =>
Env srcEs -> Env destEs -> IO (Env (es ++ destEs))
copyRefs @lentEs Env es
es Env localEs
les
case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> Env (lentEs ++ localEs)
-> ((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env (lentEs ++ localEs)
eles (((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff (lentEs ++ localEs) r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a
k ((forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a)
-> (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff (lentEs ++ localEs) r -> IO r)
-> Eff (lentEs ++ localEs) r
-> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (lentEs ++ localEs) r -> IO r
forall r. Eff (lentEs ++ localEs) r -> IO r
unlift
UnliftStrategy
SeqForkUnlift -> Env (lentEs ++ localEs)
-> ((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqForkUnliftIO Env (lentEs ++ localEs)
eles (((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff (lentEs ++ localEs) r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a
k ((forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a)
-> (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff (lentEs ++ localEs) r -> IO r)
-> Eff (lentEs ++ localEs) r
-> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (lentEs ++ localEs) r -> IO r
forall r. Eff (lentEs ++ localEs) r -> IO r
unlift
ConcUnlift Persistence
p Limit
l -> Env (lentEs ++ localEs)
-> Persistence
-> Limit
-> ((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a)
-> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
concUnliftIO Env (lentEs ++ localEs)
eles Persistence
p Limit
l (((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff (lentEs ++ localEs) r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff (lentEs ++ localEs) r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a
k ((forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a)
-> (forall r. Eff (lentEs ++ localEs) r -> Eff localEs r)
-> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff localEs r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff localEs r)
-> (Eff (lentEs ++ localEs) r -> IO r)
-> Eff (lentEs ++ localEs) r
-> Eff localEs r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (lentEs ++ localEs) r -> IO r
forall r. Eff (lentEs ++ localEs) r -> IO r
unlift
{-# INLINE localLend #-}
localSeqBorrow
:: forall borrowedEs es handlerEs localEs a
. (HasCallStack, KnownSubset borrowedEs localEs, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> ((forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a)
-> Eff es a
localSeqBorrow :: forall (borrowedEs :: [Effect]) (es :: [Effect])
(handlerEs :: [Effect]) (localEs :: [Effect]) a.
(HasCallStack, KnownSubset borrowedEs localEs,
SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> ((forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a)
-> Eff es a
localSeqBorrow (LocalEnv Env localEs
les) (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
k = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env (borrowedEs ++ es)
ees <- forall (es :: [Effect]) (srcEs :: [Effect]) (destEs :: [Effect]).
(HasCallStack, KnownSubset es srcEs) =>
Env srcEs -> Env destEs -> IO (Env (es ++ destEs))
copyRefs @borrowedEs Env localEs
les Env es
es
Env (borrowedEs ++ es)
-> ((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env (borrowedEs ++ es)
ees (((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff (borrowedEs ++ es) r -> IO r
unlift -> (Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
k ((forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a)
-> (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff (borrowedEs ++ es) r -> IO r)
-> Eff (borrowedEs ++ es) r
-> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (borrowedEs ++ es) r -> IO r
forall r. Eff (borrowedEs ++ es) r -> IO r
unlift
{-# INLINE localSeqBorrow #-}
localBorrow
:: forall borrowedEs es handlerEs localEs a
. (HasCallStack, KnownSubset borrowedEs localEs, SharedSuffix es handlerEs)
=> LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a)
-> Eff es a
localBorrow :: forall (borrowedEs :: [Effect]) (es :: [Effect])
(handlerEs :: [Effect]) (localEs :: [Effect]) a.
(HasCallStack, KnownSubset borrowedEs localEs,
SharedSuffix es handlerEs) =>
LocalEnv localEs handlerEs
-> UnliftStrategy
-> ((forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a)
-> Eff es a
localBorrow (LocalEnv Env localEs
les) UnliftStrategy
strategy (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
k = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
Env (borrowedEs ++ es)
ees <- forall (es :: [Effect]) (srcEs :: [Effect]) (destEs :: [Effect]).
(HasCallStack, KnownSubset es srcEs) =>
Env srcEs -> Env destEs -> IO (Env (es ++ destEs))
copyRefs @borrowedEs Env localEs
les Env es
es
case UnliftStrategy
strategy of
UnliftStrategy
SeqUnlift -> Env (borrowedEs ++ es)
-> ((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env (borrowedEs ++ es)
ees (((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff (borrowedEs ++ es) r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
k ((forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a)
-> (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff (borrowedEs ++ es) r -> IO r)
-> Eff (borrowedEs ++ es) r
-> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (borrowedEs ++ es) r -> IO r
forall r. Eff (borrowedEs ++ es) r -> IO r
unlift
UnliftStrategy
SeqForkUnlift -> Env (borrowedEs ++ es)
-> ((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqForkUnliftIO Env (borrowedEs ++ es)
ees (((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff (borrowedEs ++ es) r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
k ((forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a)
-> (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff (borrowedEs ++ es) r -> IO r)
-> Eff (borrowedEs ++ es) r
-> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (borrowedEs ++ es) r -> IO r
forall r. Eff (borrowedEs ++ es) r -> IO r
unlift
ConcUnlift Persistence
p Limit
l -> Env (borrowedEs ++ es)
-> Persistence
-> Limit
-> ((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a)
-> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es
-> Persistence
-> Limit
-> ((forall r. Eff es r -> IO r) -> IO a)
-> IO a
concUnliftIO Env (borrowedEs ++ es)
ees Persistence
p Limit
l (((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff (borrowedEs ++ es) r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff (borrowedEs ++ es) r -> IO r
unlift -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
k ((forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a)
-> (forall r. Eff (borrowedEs ++ es) r -> Eff es r) -> Eff es a
forall a b. (a -> b) -> a -> b
$ IO r -> Eff es r
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO r -> Eff es r)
-> (Eff (borrowedEs ++ es) r -> IO r)
-> Eff (borrowedEs ++ es) r
-> Eff es r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (borrowedEs ++ es) r -> IO r
forall r. Eff (borrowedEs ++ es) r -> IO r
unlift
{-# INLINE localBorrow #-}
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 '[] '[]
interpretImpl
:: (HasCallStack, DispatchOf e ~ Dynamic)
=> Eff (e : es) a
-> HandlerImpl e es
-> Eff es a
interpretImpl :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Eff (e : es) a -> HandlerImpl e es -> Eff es a
interpretImpl Eff (e : es) a
action HandlerImpl e es
handlerImpl = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ Handler e -> Eff (e : es) a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Handler e -> Eff (e : es) a -> Eff es a
runHandler (Env es -> HandlerImpl e es -> Handler e
forall (handlerEs :: [Effect]) (a :: Effect).
Env handlerEs -> HandlerImpl a handlerEs -> Handler a
Handler Env es
es HandlerImpl e es
handlerImpl) Eff (e : es) a
action
{-# INLINE interpretImpl #-}
reinterpretImpl
:: (HasCallStack, DispatchOf e ~ Dynamic)
=> (Eff handlerEs a -> Eff es b)
-> Eff (e : es) a
-> HandlerImpl e handlerEs
-> Eff es b
reinterpretImpl :: forall (e :: Effect) (handlerEs :: [Effect]) a (es :: [Effect]) b.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> Eff (e : es) a -> HandlerImpl e handlerEs -> Eff es b
reinterpretImpl Eff handlerEs a -> Eff es b
runSetup Eff (e : es) a
action HandlerImpl e handlerEs
handlerImpl = (Env es -> IO b) -> Eff es b
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO b) -> Eff es b) -> (Env es -> IO b) -> Eff es b
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
(Eff es b -> Env es -> IO b
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es b -> IO b)
-> ((Env handlerEs -> IO a) -> Eff es b)
-> (Env handlerEs -> IO a)
-> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff handlerEs a -> Eff es b
runSetup (Eff handlerEs a -> Eff es b)
-> ((Env handlerEs -> IO a) -> Eff handlerEs a)
-> (Env handlerEs -> IO a)
-> Eff es b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Env handlerEs -> IO a) -> Eff handlerEs a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env handlerEs -> IO a) -> IO b)
-> (Env handlerEs -> IO a) -> IO b
forall a b. (a -> b) -> a -> b
$ \Env handlerEs
handlerEs -> do
(Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
es) (Eff es a -> IO a) -> Eff es a -> IO a
forall a b. (a -> b) -> a -> b
$ Handler e -> Eff (e : es) a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
Handler e -> Eff (e : es) a -> Eff es a
runHandler (Env handlerEs -> HandlerImpl e handlerEs -> Handler e
forall (handlerEs :: [Effect]) (a :: Effect).
Env handlerEs -> HandlerImpl a handlerEs -> Handler a
Handler Env handlerEs
handlerEs HandlerImpl e handlerEs
handlerImpl) Eff (e : es) a
action
{-# INLINE reinterpretImpl #-}
interposeImpl
:: forall e es a. (HasCallStack, DispatchOf e ~ Dynamic, e :> es)
=> Eff es a
-> HandlerImpl e es
-> Eff es a
interposeImpl :: forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
Eff es a -> HandlerImpl e es -> Eff es a
interposeImpl Eff es a
action HandlerImpl e es
handlerImpl = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
IO (Env es) -> (Env es -> IO ()) -> (Env es -> IO a) -> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
inlineBracket
(do
Handler e
origHandler <- forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv @e Env es
es
EffectRep (DispatchOf e) e
-> Relinker (EffectRep (DispatchOf e)) e -> Env es -> IO (Env es)
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
EffectRep (DispatchOf e) e
-> Relinker (EffectRep (DispatchOf e)) e -> Env es -> IO (Env es)
replaceEnv EffectRep (DispatchOf e) e
Handler e
origHandler Relinker (EffectRep (DispatchOf e)) e
Relinker Handler e
forall (e :: Effect). Relinker Handler e
relinkHandler Env es
es
)
(\Env es
newEs -> do
Env es -> EffectRep (DispatchOf e) e -> IO ()
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> EffectRep (DispatchOf e) e -> IO ()
putEnv Env es
es (EffectRep (DispatchOf e) e -> IO ())
-> IO (EffectRep (DispatchOf e) e) -> IO ()
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv @e Env es
newEs
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> IO ()
unreplaceEnv @e Env es
newEs
)
(\Env es
newEs -> do
Env es -> EffectRep (DispatchOf e) e -> IO ()
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> EffectRep (DispatchOf e) e -> IO ()
putEnv Env es
es (EffectRep (DispatchOf e) e -> IO ())
-> EffectRep (DispatchOf e) e -> IO ()
forall a b. (a -> b) -> a -> b
$ Env es -> HandlerImpl e es -> Handler e
forall (handlerEs :: [Effect]) (a :: Effect).
Env handlerEs -> HandlerImpl a handlerEs -> Handler a
Handler Env es
newEs HandlerImpl e es
handlerImpl
Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff Eff es a
action Env es
es
)
{-# INLINE interposeImpl #-}
imposeImpl
:: forall e es handlerEs a b. (HasCallStack, DispatchOf e ~ Dynamic, e :> es)
=> (Eff handlerEs a -> Eff es b)
-> Eff es a
-> HandlerImpl e handlerEs
-> Eff es b
imposeImpl :: forall (e :: Effect) (es :: [Effect]) (handlerEs :: [Effect]) a b.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
(Eff handlerEs a -> Eff es b)
-> Eff es a -> HandlerImpl e handlerEs -> Eff es b
imposeImpl Eff handlerEs a -> Eff es b
runSetup Eff es a
action HandlerImpl e handlerEs
handlerImpl = (Env es -> IO b) -> Eff es b
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO b) -> Eff es b) -> (Env es -> IO b) -> Eff es b
forall a b. (a -> b) -> a -> b
$ \Env es
es -> do
IO (Env es) -> (Env es -> IO ()) -> (Env es -> IO b) -> IO b
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
inlineBracket
(do
Handler e
origHandler <- forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv @e Env es
es
EffectRep (DispatchOf e) e
-> Relinker (EffectRep (DispatchOf e)) e -> Env es -> IO (Env es)
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
EffectRep (DispatchOf e) e
-> Relinker (EffectRep (DispatchOf e)) e -> Env es -> IO (Env es)
replaceEnv EffectRep (DispatchOf e) e
Handler e
origHandler Relinker (EffectRep (DispatchOf e)) e
Relinker Handler e
forall (e :: Effect). Relinker Handler e
relinkHandler Env es
es
)
(\Env es
newEs -> do
Env es -> EffectRep (DispatchOf e) e -> IO ()
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> EffectRep (DispatchOf e) e -> IO ()
putEnv Env es
es (EffectRep (DispatchOf e) e -> IO ())
-> IO (EffectRep (DispatchOf e) e) -> IO ()
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> IO (EffectRep (DispatchOf e) e)
getEnv @e Env es
newEs
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> IO ()
unreplaceEnv @e Env es
newEs
)
(\Env es
newEs -> do
(Eff es b -> Env es -> IO b
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
`unEff` Env es
newEs) (Eff es b -> IO b)
-> ((Env handlerEs -> IO a) -> Eff es b)
-> (Env handlerEs -> IO a)
-> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff handlerEs a -> Eff es b
runSetup (Eff handlerEs a -> Eff es b)
-> ((Env handlerEs -> IO a) -> Eff handlerEs a)
-> (Env handlerEs -> IO a)
-> Eff es b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Env handlerEs -> IO a) -> Eff handlerEs a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env handlerEs -> IO a) -> IO b)
-> (Env handlerEs -> IO a) -> IO b
forall a b. (a -> b) -> a -> b
$ \Env handlerEs
handlerEs -> do
Env es -> EffectRep (DispatchOf e) e -> IO ()
forall (e :: Effect) (es :: [Effect]).
(HasCallStack, e :> es) =>
Env es -> EffectRep (DispatchOf e) e -> IO ()
putEnv Env es
es (EffectRep (DispatchOf e) e -> IO ())
-> EffectRep (DispatchOf e) e -> IO ()
forall a b. (a -> b) -> a -> b
$ Env handlerEs -> HandlerImpl e handlerEs -> Handler e
forall (handlerEs :: [Effect]) (a :: Effect).
Env handlerEs -> HandlerImpl a handlerEs -> Handler a
Handler Env handlerEs
handlerEs HandlerImpl e handlerEs
handlerImpl
Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff Eff es a
action Env es
es
)
{-# INLINE imposeImpl #-}
copyRefs
:: forall es srcEs destEs
. (HasCallStack, KnownSubset es srcEs)
=> Env srcEs
-> Env destEs
-> IO (Env (es ++ destEs))
copyRefs :: forall (es :: [Effect]) (srcEs :: [Effect]) (destEs :: [Effect]).
(HasCallStack, KnownSubset es srcEs) =>
Env srcEs -> Env destEs -> IO (Env (es ++ destEs))
copyRefs src :: Env srcEs
src@(Env Int
soffset PrimArray Ref
srefs IORef' Storage
_) dest :: Env destEs
dest@(Env Int
doffset PrimArray Ref
drefs IORef' Storage
storage) = do
Env srcEs -> Env destEs -> IO ()
forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env srcEs
src Env destEs
dest
let es :: [Int]
es = forall (subEs :: [Effect]) (es :: [Effect]).
Subset subEs es =>
[Int]
reifyIndices @es @srcEs
esSize :: Int
esSize = [Int] -> Int
forall a. [a] -> Int
forall (t :: Type -> Type) a. Foldable t => t a -> Int
length [Int]
es
destSize :: Int
destSize = PrimArray Ref -> Int
forall a. Prim a => PrimArray a -> Int
sizeofPrimArray PrimArray Ref
drefs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
doffset
MutablePrimArray RealWorld Ref
mrefs <- Int -> IO (MutablePrimArray (PrimState IO) Ref)
forall (m :: Type -> Type) a.
(PrimMonad m, Prim a) =>
Int -> m (MutablePrimArray (PrimState m) a)
newPrimArray (Int
esSize Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
destSize)
MutablePrimArray (PrimState IO) Ref
-> Int -> PrimArray Ref -> Int -> Int -> IO ()
forall (m :: Type -> Type) a.
(PrimMonad m, Prim a) =>
MutablePrimArray (PrimState m) a
-> Int -> PrimArray a -> Int -> Int -> m ()
copyPrimArray MutablePrimArray RealWorld Ref
MutablePrimArray (PrimState IO) Ref
mrefs Int
esSize PrimArray Ref
drefs Int
doffset Int
destSize
let writeRefs :: Int -> [Int] -> IO ()
writeRefs Int
i = \case
[] -> () -> IO ()
forall a. a -> IO a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ()
(Int
x : [Int]
xs) -> do
MutablePrimArray (PrimState IO) Ref -> Int -> Ref -> IO ()
forall a (m :: Type -> Type).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray RealWorld Ref
MutablePrimArray (PrimState IO) Ref
mrefs Int
i (Ref -> IO ()) -> Ref -> IO ()
forall a b. (a -> b) -> a -> b
$ PrimArray Ref -> Int -> Ref
forall a. Prim a => PrimArray a -> Int -> a
indexPrimArray PrimArray Ref
srefs (Int
soffset Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x)
Int -> [Int] -> IO ()
writeRefs (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [Int]
xs
Int -> [Int] -> IO ()
writeRefs Int
0 [Int]
es
PrimArray Ref
refs <- MutablePrimArray (PrimState IO) Ref -> IO (PrimArray Ref)
forall (m :: Type -> Type) a.
PrimMonad m =>
MutablePrimArray (PrimState m) a -> m (PrimArray a)
unsafeFreezePrimArray MutablePrimArray RealWorld Ref
MutablePrimArray (PrimState IO) Ref
mrefs
Env (es ++ destEs) -> IO (Env (es ++ destEs))
forall a. a -> IO a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (Env (es ++ destEs) -> IO (Env (es ++ destEs)))
-> Env (es ++ destEs) -> IO (Env (es ++ destEs))
forall a b. (a -> b) -> a -> b
$ Int -> PrimArray Ref -> IORef' Storage -> Env (es ++ destEs)
forall (es :: [Effect]).
Int -> PrimArray Ref -> IORef' Storage -> Env es
Env Int
0 PrimArray Ref
refs IORef' Storage
storage
{-# NOINLINE copyRefs #-}
requireMatchingStorages :: HasCallStack => Env es1 -> Env es2 -> IO ()
requireMatchingStorages :: forall (es1 :: [Effect]) (es2 :: [Effect]).
HasCallStack =>
Env es1 -> Env es2 -> IO ()
requireMatchingStorages Env es1
es1 Env es2
es2
| Env es1 -> IORef' Storage
forall (es :: [Effect]). Env es -> IORef' Storage
envStorage Env es1
es1 IORef' Storage -> IORef' Storage -> Bool
forall a. Eq a => a -> a -> Bool
/= Env es2 -> IORef' Storage
forall (es :: [Effect]). Env es -> IORef' Storage
envStorage Env es2
es2 = [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error
([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
"Env and LocalEnv point to different Storages.\n"
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"If you passed LocalEnv to a different thread and tried to create an "
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"unlifting function there, it's not allowed. You need to create it in "
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"the thread of the effect handler."
| Bool
otherwise = () -> IO ()
forall a. a -> IO a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ()