{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE UndecidableInstances #-}
module Effectful.Dispatch.Dynamic
(
send
, 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 Data.Primitive.PrimArray
import GHC.Stack (HasCallStack)
import GHC.TypeLits
import Effectful.Internal.Effect
import Effectful.Internal.Env
import Effectful.Internal.Monad
import Effectful.Internal.Utils
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
m = (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 -> Handler e
mkHandler Env es
es) Eff (e : es) a
m
where
mkHandler :: Env es -> Handler e
mkHandler Env es
es = Env es -> EffectHandler e es -> Handler e
forall (handlerEs :: [Effect]) (a :: Effect).
Env handlerEs -> EffectHandler a handlerEs -> Handler a
Handler Env es
es (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
m EffectHandler e es
handler = EffectHandler e es -> Eff (e : es) a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
EffectHandler e es -> Eff (e : es) a -> Eff es a
interpret LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
EffectHandler e es
handler Eff (e : es) a
m
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
runHandlerEs EffectHandler e handlerEs
handler Eff (e : es) a
m = (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
runHandlerEs (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 -> Handler e
mkHandler Env handlerEs
handlerEs) Eff (e : es) a
m
where
mkHandler :: Env handlerEs -> Handler e
mkHandler Env handlerEs
es = Env handlerEs -> EffectHandler e handlerEs -> Handler e
forall (handlerEs :: [Effect]) (a :: Effect).
Env handlerEs -> EffectHandler a handlerEs -> Handler a
Handler Env handlerEs
es (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
runHandlerEs Eff (e : es) a
m EffectHandler e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff (e : es) a -> Eff es b
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
runHandlerEs LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a
EffectHandler e handlerEs
handler Eff (e : es) a
m
interpose
:: forall e es a. (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
m = (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 -> Handler e
mkHandler Env es
newEs
Eff es a -> Env es -> IO a
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 = Env es -> EffectHandler e es -> Handler e
forall (handlerEs :: [Effect]) (a :: Effect).
Env handlerEs -> EffectHandler a handlerEs -> Handler a
Handler Env es
es (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
m EffectHandler e es
handler = EffectHandler e es -> Eff es a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
EffectHandler e es -> Eff es a -> Eff es a
interpose LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
EffectHandler e es
handler Eff es a
m
impose
:: forall e es handlerEs a b. (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
runHandlerEs EffectHandler e handlerEs
handler Eff es a
m = (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
runHandlerEs (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 -> Handler e
mkHandler Env handlerEs
handlerEs
Eff es a -> Env es -> IO a
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 = Env handlerEs -> EffectHandler e handlerEs -> Handler e
forall (handlerEs :: [Effect]) (a :: Effect).
Env handlerEs -> EffectHandler a handlerEs -> Handler a
Handler Env handlerEs
es (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
runHandlerEs Eff es a
m EffectHandler e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff es a -> Eff es b
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
runHandlerEs LocalEnv localEs handlerEs -> e (Eff localEs) a -> Eff handlerEs a
EffectHandler e handlerEs
handler Eff es a
m
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 = EffectHandler e es -> Eff (e : es) a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
EffectHandler e es -> Eff (e : es) a -> Eff es a
interpret ((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
m EffectHandler_ e es
handler = EffectHandler e es -> Eff (e : es) a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
EffectHandler e es -> Eff (e : es) a -> Eff es a
interpret ((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) Eff (e : es) a
m
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
runHandlerEs EffectHandler_ e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff (e : es) a -> Eff es b
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
runHandlerEs ((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
runHandlerEs Eff (e : es) a
m EffectHandler_ e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff (e : es) a -> Eff es b
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
runHandlerEs ((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) Eff (e : es) a
m
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 = EffectHandler e es -> Eff es a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
EffectHandler e es -> Eff es a -> Eff es a
interpose ((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
m EffectHandler_ e es
handler = EffectHandler e es -> Eff es a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
EffectHandler e es -> Eff es a -> Eff es a
interpose ((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) Eff es a
m
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
runHandlerEs EffectHandler_ e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff es a -> Eff es b
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
runHandlerEs ((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
runHandlerEs Eff es a
m EffectHandler_ e handlerEs
handler = (Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff es a -> Eff es b
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
runHandlerEs ((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) Eff es a
m
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 #-}
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 ()
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 '[] '[]