{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE UnboxedTuples #-}
{-# OPTIONS_HADDOCK not-home #-}
module Cleff.Internal.Interpret
(
adjust, raise, raiseN, inject, subsume, subsumeN, raiseUnder, raiseNUnder, raiseUnderN, raiseNUnderN
,
Handling, esSend, Handler, Translator
,
interpret, reinterpret, reinterpret2, reinterpret3, reinterpretN, interpose, impose, imposeN
,
transform, translate
,
toEff, toEffWith, withFromEff
) where
import Cleff.Internal.Effect
import Cleff.Internal.Monad
import Data.Rec.SmallArray (Rec, pattern (:++:))
import qualified Data.Rec.SmallArray as Rec
import Unsafe.Coerce (unsafeCoerce)
adjust :: ∀ es es'. (∀ f. Rec f es' -> Rec f es) -> Eff es ~> Eff es'
adjust :: (forall (f :: Effect -> Type). Rec f es' -> Rec f es)
-> Eff es ~> Eff es'
adjust forall (f :: Effect -> Type). Rec f es' -> Rec f es
f Eff es a
m = (Env es' -> IO a) -> Eff es' a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
Eff (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 -> IO a) -> (Env es' -> Env es) -> Env es' -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rec HandlerPtr es' -> Rec HandlerPtr es) -> Env es' -> Env es
forall (es' :: [Effect]) (es :: [Effect]).
(Rec HandlerPtr es -> Rec HandlerPtr es') -> Env es -> Env es'
adjustEnv Rec HandlerPtr es' -> Rec HandlerPtr es
forall (f :: Effect -> Type). Rec f es' -> Rec f es
f)
raise :: ∀ e es. Eff es ~> Eff (e ': es)
raise :: Eff es a -> Eff (e : es) a
raise = forall (es :: [Effect]).
KnownList '[e] =>
Eff es ~> Eff ('[e] ++ es)
forall (es' :: [Effect]) (es :: [Effect]).
KnownList es' =>
Eff es ~> Eff (es' ++ es)
raiseN @'[e]
raiseN :: ∀ es' es. KnownList es' => Eff es ~> Eff (es' ++ es)
raiseN :: Eff es ~> Eff (es' ++ es)
raiseN = (forall (f :: Effect -> Type). Rec f (es' ++ es) -> Rec f es)
-> Eff es ~> Eff (es' ++ es)
forall (es :: [Effect]) (es' :: [Effect]).
(forall (f :: Effect -> Type). Rec f es' -> Rec f es)
-> Eff es ~> Eff es'
adjust (forall (es' :: [Effect]) (f :: Effect -> Type).
KnownList es' =>
Rec f (es' ++ es') -> Rec f es'
forall k (es :: [k]) (es' :: [k]) (f :: k -> Type).
KnownList es =>
Rec f (es ++ es') -> Rec f es'
Rec.drop @es')
raiseUnder :: ∀ e' e es. Eff (e ': es) ~> Eff (e ': e' ': es)
raiseUnder :: Eff (e : es) a -> Eff (e : e' : es) a
raiseUnder = forall (es' :: [Effect]) (e :: Effect) (es :: [Effect]).
KnownList es' =>
Eff (e : es) ~> Eff (e : (es' ++ es))
forall (e :: Effect) (es :: [Effect]).
KnownList '[e'] =>
Eff (e : es) ~> Eff (e : ('[e'] ++ es))
raiseNUnder @'[e']
raiseNUnder :: ∀ es' e es. KnownList es' => Eff (e ': es) ~> Eff (e ': es' ++ es)
raiseNUnder :: Eff (e : es) ~> Eff (e : (es' ++ es))
raiseNUnder = forall (es :: [Effect]).
(KnownList '[e], KnownList es') =>
Eff ('[e] ++ es) ~> Eff ('[e] ++ (es' ++ es))
forall (es'' :: [Effect]) (es' :: [Effect]) (es :: [Effect]).
(KnownList es', KnownList es'') =>
Eff (es' ++ es) ~> Eff (es' ++ (es'' ++ es))
raiseNUnderN @es' @'[e]
raiseUnderN :: ∀ e es' es. KnownList es' => Eff (es' ++ es) ~> Eff (es' ++ e ': es)
raiseUnderN :: Eff (es' ++ es) ~> Eff (es' ++ (e : es))
raiseUnderN = (KnownList es', KnownList '[e]) =>
Eff (es' ++ es) ~> Eff (es' ++ ('[e] ++ es))
forall (es'' :: [Effect]) (es' :: [Effect]) (es :: [Effect]).
(KnownList es', KnownList es'') =>
Eff (es' ++ es) ~> Eff (es' ++ (es'' ++ es))
raiseNUnderN @'[e] @es' @es
raiseNUnderN :: ∀ es'' es' es. (KnownList es', KnownList es'') => Eff (es' ++ es) ~> Eff (es' ++ (es'' ++ es))
raiseNUnderN :: Eff (es' ++ es) ~> Eff (es' ++ (es'' ++ es))
raiseNUnderN = (forall (f :: Effect -> Type).
Rec f (es' ++ (es'' ++ es)) -> Rec f (es' ++ es))
-> Eff (es' ++ es) ~> Eff (es' ++ (es'' ++ es))
forall (es :: [Effect]) (es' :: [Effect]).
(forall (f :: Effect -> Type). Rec f es' -> Rec f es)
-> Eff es ~> Eff es'
adjust \Rec f (es' ++ (es'' ++ es))
re -> Rec f es' -> Rec f es -> Rec f (es' ++ es)
forall a (f :: a -> Type) (es :: [a]) (es' :: [a]).
Rec f es -> Rec f es' -> Rec f (es ++ es')
Rec.concat
(Rec f (es' ++ (es'' ++ es)) -> Rec f es'
forall k (es :: [k]) (es' :: [k]) (f :: k -> Type).
KnownList es =>
Rec f (es ++ es') -> Rec f es
Rec.take @es' @(es'' ++ es) Rec f (es' ++ (es'' ++ es))
re) (Rec f (es'' ++ es) -> Rec f es
forall k (es :: [k]) (es' :: [k]) (f :: k -> Type).
KnownList es =>
Rec f (es ++ es') -> Rec f es'
Rec.drop @es'' @es (Rec f (es' ++ (es'' ++ es)) -> Rec f (es'' ++ es)
forall k (es :: [k]) (es' :: [k]) (f :: k -> Type).
KnownList es =>
Rec f (es ++ es') -> Rec f es'
Rec.drop @es' @(es'' ++ es) Rec f (es' ++ (es'' ++ es))
re))
inject :: ∀ es' es. Subset es' es => Eff es' ~> Eff es
inject :: Eff es' ~> Eff es
inject = (forall (f :: Effect -> Type). Rec f es -> Rec f es')
-> Eff es' ~> Eff es
forall (es :: [Effect]) (es' :: [Effect]).
(forall (f :: Effect -> Type). Rec f es' -> Rec f es)
-> Eff es ~> Eff es'
adjust (forall (es' :: [Effect]) (f :: Effect -> Type).
Subset es' es' =>
Rec f es' -> Rec f es'
forall k (es :: [k]) (es' :: [k]) (f :: k -> Type).
Subset es es' =>
Rec f es' -> Rec f es
Rec.pick @es')
subsume :: ∀ e es. e :> es => Eff (e ': es) ~> Eff es
subsume :: Eff (e : es) ~> Eff es
subsume = forall (es :: [Effect]).
Subset '[e] es =>
Eff ('[e] ++ es) ~> Eff es
forall (es' :: [Effect]) (es :: [Effect]).
Subset es' es =>
Eff (es' ++ es) ~> Eff es
subsumeN @'[e]
subsumeN :: ∀ es' es. Subset es' es => Eff (es' ++ es) ~> Eff es
subsumeN :: Eff (es' ++ es) ~> Eff es
subsumeN = (forall (f :: Effect -> Type). Rec f es -> Rec f (es' ++ es))
-> Eff (es' ++ es) ~> Eff es
forall (es :: [Effect]) (es' :: [Effect]).
(forall (f :: Effect -> Type). Rec f es' -> Rec f es)
-> Eff es ~> Eff es'
adjust \Rec f es
re -> Rec f es -> Rec f es'
forall k (es :: [k]) (es' :: [k]) (f :: k -> Type).
Subset es es' =>
Rec f es' -> Rec f es
Rec.pick @es' Rec f es
re Rec f es' -> Rec f es -> Rec f (es' ++ es)
forall a (es :: [a]) (es' :: [a]) (f :: a -> Type).
KnownList es =>
Rec f es -> Rec f es' -> Rec f (es ++ es')
:++: Rec f es
re
data SendSite esSend e = SendSite
{-# UNPACK #-} !(Env esSend)
{-# UNPACK #-} !(HandlerPtr e)
class Handling esSend e es | esSend -> e es where
sendSite :: SendSite esSend e
sendSite = [Char] -> SendSite esSend e
forall a. HasCallStack => [Char] -> a
error
[Char]
"Cleff.Internal.Interpret.sendSite: Attempting to access the send site without a reflected value. This is perhaps \
\because you are trying to define an instance for the 'Handling' typeclass, which you should not be doing \
\whatsoever. If that or other shenanigans seem unlikely, please report this as a bug."
hdlPtr :: ∀ esSend e es. Handling esSend e es => HandlerPtr e
hdlPtr :: HandlerPtr e
hdlPtr = let SendSite Env esSend
_ HandlerPtr e
ptr = forall k (esSend :: [Effect]) (e :: Effect) (es :: k).
Handling esSend e es =>
SendSite esSend e
forall (e :: Effect) (es :: k).
Handling esSend e es =>
SendSite esSend e
sendSite @esSend in HandlerPtr e
ptr
{-# INLINE hdlPtr #-}
esSend :: Handling esSend e es => Env esSend
esSend :: Env esSend
esSend = let SendSite Env esSend
env HandlerPtr e
_ = SendSite esSend e
forall k (esSend :: [Effect]) (e :: Effect) (es :: k).
Handling esSend e es =>
SendSite esSend e
sendSite in Env esSend
env
{-# INLINE esSend #-}
newtype InstHandling esSend e es a = InstHandling (Handling esSend e es => a)
instHandling :: ∀ esSend e es a. (Handling esSend e es => a) -> SendSite esSend e -> a
instHandling :: (Handling esSend e es => a) -> SendSite esSend e -> a
instHandling Handling esSend e es => a
x = InstHandling esSend e es a -> SendSite esSend e -> a
forall a b. a -> b
unsafeCoerce ((Handling esSend e es => a) -> InstHandling esSend e es a
forall k (esSend :: [Effect]) (e :: Effect) (es :: k) a.
(Handling esSend e es => a) -> InstHandling esSend e es a
InstHandling Handling esSend e es => a
x :: InstHandling esSend e es a)
{-# INLINE instHandling #-}
type Handler e es = ∀ esSend. Handling esSend e es => e (Eff esSend) ~> Eff es
type Translator e e' = ∀ esSend. e (Eff esSend) ~> e' (Eff esSend)
mkInternalHandler :: HandlerPtr e -> Env es -> Handler e es -> InternalHandler e
mkInternalHandler :: HandlerPtr e -> Env es -> Handler e es -> InternalHandler e
mkInternalHandler HandlerPtr e
ptr Env es
es Handler e es
handle = (forall (es :: [Effect]). e (Eff es) ~> Eff es)
-> InternalHandler e
forall (e :: Effect).
(forall (es :: [Effect]). e (Eff es) ~> Eff es)
-> InternalHandler e
InternalHandler \e (Eff es) a
e -> (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
Eff \Env es
ess ->
Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff ((Handling es e es => e (Eff es) a -> Eff es a)
-> SendSite es e -> e (Eff es) a -> Eff es a
forall k (esSend :: [Effect]) (e :: Effect) (es :: k) a.
(Handling esSend e es => a) -> SendSite esSend e -> a
instHandling Handling es e es => e (Eff es) a -> Eff es a
Handler e es
handle (Env es -> HandlerPtr e -> SendSite es e
forall (esSend :: [Effect]) (e :: Effect).
Env esSend -> HandlerPtr e -> SendSite esSend e
SendSite Env es
ess HandlerPtr e
ptr) e (Eff es) a
e) (Env es -> Env es -> Env es
forall (es :: [Effect]) (es' :: [Effect]).
Env es' -> Env es -> Env es
updateEnv Env es
ess Env es
es)
interpret :: ∀ e es. Handler e es -> Eff (e ': es) ~> Eff es
interpret :: Handler e es -> Eff (e : es) ~> Eff es
interpret = forall (es' :: [Effect]) (e :: Effect) (es :: [Effect]).
KnownList es' =>
Handler e (es' ++ es) -> Eff (e : es) ~> Eff (es' ++ es)
forall (e :: Effect) (es :: [Effect]).
KnownList '[] =>
Handler e ('[] ++ es) -> Eff (e : es) ~> Eff ('[] ++ es)
reinterpretN @'[]
reinterpret :: ∀ e' e es. Handler e (e' ': es) -> Eff (e ': es) ~> Eff (e' ': es)
reinterpret :: Handler e (e' : es) -> Eff (e : es) ~> Eff (e' : es)
reinterpret = forall (es' :: [Effect]) (e :: Effect) (es :: [Effect]).
KnownList es' =>
Handler e (es' ++ es) -> Eff (e : es) ~> Eff (es' ++ es)
forall (e :: Effect) (es :: [Effect]).
KnownList '[e'] =>
Handler e ('[e'] ++ es) -> Eff (e : es) ~> Eff ('[e'] ++ es)
reinterpretN @'[e']
reinterpret2 :: ∀ e' e'' e es. Handler e (e' ': e'' ': es) -> Eff (e ': es) ~> Eff (e' ': e'' ': es)
reinterpret2 :: Handler e (e' : e'' : es) -> Eff (e : es) ~> Eff (e' : e'' : es)
reinterpret2 = forall (es' :: [Effect]) (e :: Effect) (es :: [Effect]).
KnownList es' =>
Handler e (es' ++ es) -> Eff (e : es) ~> Eff (es' ++ es)
forall (e :: Effect) (es :: [Effect]).
KnownList '[e', e''] =>
Handler e ('[e', e''] ++ es)
-> Eff (e : es) ~> Eff ('[e', e''] ++ es)
reinterpretN @'[e', e'']
reinterpret3 :: ∀ e' e'' e''' e es. Handler e (e' ': e'' ': e''' ': es) -> Eff (e ': es) ~> Eff (e' ': e'' ': e''' ': es)
reinterpret3 :: Handler e (e' : e'' : e''' : es)
-> Eff (e : es) ~> Eff (e' : e'' : e''' : es)
reinterpret3 = forall (es' :: [Effect]) (e :: Effect) (es :: [Effect]).
KnownList es' =>
Handler e (es' ++ es) -> Eff (e : es) ~> Eff (es' ++ es)
forall (e :: Effect) (es :: [Effect]).
KnownList '[e', e'', e'''] =>
Handler e ('[e', e'', e'''] ++ es)
-> Eff (e : es) ~> Eff ('[e', e'', e'''] ++ es)
reinterpretN @'[e', e'', e''']
reinterpretN :: ∀ es' e es. KnownList es' => Handler e (es' ++ es) -> Eff (e ': es) ~> Eff (es' ++ es)
reinterpretN :: Handler e (es' ++ es) -> Eff (e : es) ~> Eff (es' ++ es)
reinterpretN Handler e (es' ++ es)
handle Eff (e : es) a
m = (Env (es' ++ es) -> IO a) -> Eff (es' ++ es) a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
Eff \Env (es' ++ es)
es ->
let (# HandlerPtr e
ptr, Env (es' ++ es)
es' #) = Env (es' ++ es) -> (# HandlerPtr e, Env (es' ++ es) #)
forall (e :: Effect) (es :: [Effect]).
Env es -> (# HandlerPtr e, Env es #)
allocaEnv Env (es' ++ es)
es
in Eff (e : es) a -> Env (e : es) -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff Eff (e : es) a
m (Env (e : es) -> IO a) -> Env (e : es) -> IO a
forall a b. (a -> b) -> a -> b
$ HandlerPtr e -> InternalHandler e -> Env es -> Env (e : es)
forall (e :: Effect) (es :: [Effect]).
HandlerPtr e -> InternalHandler e -> Env es -> Env (e : es)
appendEnv HandlerPtr e
ptr (HandlerPtr e
-> Env (es' ++ es) -> Handler e (es' ++ es) -> InternalHandler e
forall (e :: Effect) (es :: [Effect]).
HandlerPtr e -> Env es -> Handler e es -> InternalHandler e
mkInternalHandler HandlerPtr e
ptr Env (es' ++ es)
es' Handler e (es' ++ es)
handle) (Env es -> Env (e : es)) -> Env es -> Env (e : es)
forall a b. (a -> b) -> a -> b
$ (Rec HandlerPtr (es' ++ es) -> Rec HandlerPtr es)
-> Env (es' ++ es) -> Env es
forall (es' :: [Effect]) (es :: [Effect]).
(Rec HandlerPtr es -> Rec HandlerPtr es') -> Env es -> Env es'
adjustEnv (forall (es' :: [Effect]) (f :: Effect -> Type).
KnownList es' =>
Rec f (es' ++ es') -> Rec f es'
forall k (es :: [k]) (es' :: [k]) (f :: k -> Type).
KnownList es =>
Rec f (es ++ es') -> Rec f es'
Rec.drop @es') Env (es' ++ es)
es'
{-# INLINE reinterpretN #-}
interpose :: ∀ e es. e :> es => Handler e es -> Eff es ~> Eff es
interpose :: Handler e es -> Eff es ~> Eff es
interpose = forall (es' :: [Effect]) (e :: Effect) (es :: [Effect]).
(KnownList es', e :> es) =>
Handler e (es' ++ es) -> Eff es ~> Eff (es' ++ es)
forall (e :: Effect) (es :: [Effect]).
(KnownList '[], e :> es) =>
Handler e ('[] ++ es) -> Eff es ~> Eff ('[] ++ es)
imposeN @'[]
impose :: ∀ e' e es. e :> es => Handler e (e' ': es) -> Eff es ~> Eff (e' ': es)
impose :: Handler e (e' : es) -> Eff es ~> Eff (e' : es)
impose = forall (es' :: [Effect]) (e :: Effect) (es :: [Effect]).
(KnownList es', e :> es) =>
Handler e (es' ++ es) -> Eff es ~> Eff (es' ++ es)
forall (e :: Effect) (es :: [Effect]).
(KnownList '[e'], e :> es) =>
Handler e ('[e'] ++ es) -> Eff es ~> Eff ('[e'] ++ es)
imposeN @'[e']
imposeN :: ∀ es' e es. (KnownList es', e :> es) => Handler e (es' ++ es) -> Eff es ~> Eff (es' ++ es)
imposeN :: Handler e (es' ++ es) -> Eff es ~> Eff (es' ++ es)
imposeN Handler e (es' ++ es)
handle Eff es a
m = (Env (es' ++ es) -> IO a) -> Eff (es' ++ es) a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
Eff \Env (es' ++ es)
es ->
let (# HandlerPtr e
ptr, Env (es' ++ es)
es' #) = Env (es' ++ es) -> (# HandlerPtr e, Env (es' ++ es) #)
forall (e :: Effect) (es :: [Effect]).
Env es -> (# HandlerPtr e, Env es #)
allocaEnv Env (es' ++ es)
es
in 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 -> IO a) -> Env es -> IO a
forall a b. (a -> b) -> a -> b
$ HandlerPtr e -> InternalHandler e -> Env es -> Env es
forall (e :: Effect) (es :: [Effect]).
Elem e es =>
HandlerPtr e -> InternalHandler e -> Env es -> Env es
replaceEnv HandlerPtr e
ptr (HandlerPtr e
-> Env (es' ++ es) -> Handler e (es' ++ es) -> InternalHandler e
forall (e :: Effect) (es :: [Effect]).
HandlerPtr e -> Env es -> Handler e es -> InternalHandler e
mkInternalHandler HandlerPtr e
ptr Env (es' ++ es)
es' Handler e (es' ++ es)
handle) (Env es -> Env es) -> Env es -> Env es
forall a b. (a -> b) -> a -> b
$ (Rec HandlerPtr (es' ++ es) -> Rec HandlerPtr es)
-> Env (es' ++ es) -> Env es
forall (es' :: [Effect]) (es :: [Effect]).
(Rec HandlerPtr es -> Rec HandlerPtr es') -> Env es -> Env es'
adjustEnv (forall (es' :: [Effect]) (f :: Effect -> Type).
KnownList es' =>
Rec f (es' ++ es') -> Rec f es'
forall k (es :: [k]) (es' :: [k]) (f :: k -> Type).
KnownList es =>
Rec f (es ++ es') -> Rec f es'
Rec.drop @es') Env (es' ++ es)
es'
{-# INLINE imposeN #-}
transform :: ∀ e e' es. e' :> es => Translator e e' -> Eff (e ': es) ~> Eff es
transform :: Translator e e' -> Eff (e : es) ~> Eff es
transform Translator e e'
trans = Handler e es -> Eff (e : es) ~> Eff es
forall (e :: Effect) (es :: [Effect]).
Handler e es -> Eff (e : es) ~> Eff es
interpret ((Eff esSend ~> Eff es) -> e' (Eff esSend) ~> Eff es
forall (e :: Effect) (es' :: [Effect]) (es :: [Effect]).
(e :> es') =>
(Eff es ~> Eff es') -> e (Eff es) ~> Eff es'
sendVia forall (esSend :: [Effect]) (e :: Effect) (es :: [Effect]).
Handling esSend e es =>
Eff esSend ~> Eff es
Eff esSend ~> Eff es
toEff (e' (Eff esSend) a -> Eff es a)
-> (e (Eff esSend) a -> e' (Eff esSend) a)
-> e (Eff esSend) a
-> Eff es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e (Eff esSend) a -> e' (Eff esSend) a
Translator e e'
trans)
translate :: ∀ e e' es. Translator e e' -> Eff (e ': es) ~> Eff (e' ': es)
translate :: Translator e e' -> Eff (e : es) ~> Eff (e' : es)
translate Translator e e'
trans = Handler e (e' : es) -> Eff (e : es) ~> Eff (e' : es)
forall (e' :: Effect) (e :: Effect) (es :: [Effect]).
Handler e (e' : es) -> Eff (e : es) ~> Eff (e' : es)
reinterpret ((Eff esSend ~> Eff (e' : es)) -> e' (Eff esSend) ~> Eff (e' : es)
forall (e :: Effect) (es' :: [Effect]) (es :: [Effect]).
(e :> es') =>
(Eff es ~> Eff es') -> e (Eff es) ~> Eff es'
sendVia forall (esSend :: [Effect]) (e :: Effect) (es :: [Effect]).
Handling esSend e es =>
Eff esSend ~> Eff es
Eff esSend ~> Eff (e' : es)
toEff (e' (Eff esSend) a -> Eff (e' : es) a)
-> (e (Eff esSend) a -> e' (Eff esSend) a)
-> e (Eff esSend) a
-> Eff (e' : es) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e (Eff esSend) a -> e' (Eff esSend) a
Translator e e'
trans)
toEff :: Handling esSend e es => Eff esSend ~> Eff es
toEff :: Eff esSend ~> Eff es
toEff Eff esSend a
m = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
Eff \Env es
es -> Eff esSend a -> Env esSend -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff Eff esSend a
m (Env es -> Env esSend -> Env esSend
forall (es :: [Effect]) (es' :: [Effect]).
Env es' -> Env es -> Env es
updateEnv Env es
es Env esSend
forall k (esSend :: [Effect]) (e :: Effect) (es :: k).
Handling esSend e es =>
Env esSend
esSend)
toEffWith :: ∀ esSend e es. Handling esSend e es => Handler e es -> Eff esSend ~> Eff es
toEffWith :: Handler e es -> Eff esSend ~> Eff es
toEffWith Handler e es
handle Eff esSend a
m = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
Eff \Env es
es -> Eff esSend a -> Env esSend -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff Eff esSend a
m (Env esSend -> IO a) -> Env esSend -> IO a
forall a b. (a -> b) -> a -> b
$
HandlerPtr e -> InternalHandler e -> Env esSend -> Env esSend
forall (e :: Effect) (es :: [Effect]).
HandlerPtr e -> InternalHandler e -> Env es -> Env es
writeEnv (forall k (esSend :: [Effect]) (e :: Effect) (es :: k).
Handling esSend e es =>
HandlerPtr e
forall (e :: Effect) (es :: [Effect]).
Handling esSend e es =>
HandlerPtr e
hdlPtr @esSend) (HandlerPtr e -> Env es -> Handler e es -> InternalHandler e
forall (e :: Effect) (es :: [Effect]).
HandlerPtr e -> Env es -> Handler e es -> InternalHandler e
mkInternalHandler (forall k (esSend :: [Effect]) (e :: Effect) (es :: k).
Handling esSend e es =>
HandlerPtr e
forall (e :: Effect) (es :: [Effect]).
Handling esSend e es =>
HandlerPtr e
hdlPtr @esSend) Env es
es Handler e es
handle) (Env esSend -> Env esSend) -> Env esSend -> Env esSend
forall a b. (a -> b) -> a -> b
$ Env es -> Env esSend -> Env esSend
forall (es :: [Effect]) (es' :: [Effect]).
Env es' -> Env es -> Env es
updateEnv Env es
es Env esSend
forall k (esSend :: [Effect]) (e :: Effect) (es :: k).
Handling esSend e es =>
Env esSend
esSend
withFromEff :: Handling esSend e es => ((Eff es ~> Eff esSend) -> Eff esSend a) -> Eff es a
withFromEff :: ((Eff es ~> Eff esSend) -> Eff esSend a) -> Eff es a
withFromEff (Eff es ~> Eff esSend) -> Eff esSend a
f = (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
Eff \Env es
es -> Eff esSend a -> Env esSend -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff ((Eff es ~> Eff esSend) -> Eff esSend a
f \Eff es a
m -> (Env esSend -> IO a) -> Eff esSend a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
Eff \Env esSend
ess -> Eff es a -> Env es -> IO a
forall (es :: [Effect]) a. Eff es a -> Env es -> IO a
unEff Eff es a
m (Env esSend -> Env es -> Env es
forall (es :: [Effect]) (es' :: [Effect]).
Env es' -> Env es -> Env es
updateEnv Env esSend
ess Env es
es)) (Env es -> Env esSend -> Env esSend
forall (es :: [Effect]) (es' :: [Effect]).
Env es' -> Env es -> Env es
updateEnv Env es
es Env esSend
forall k (esSend :: [Effect]) (e :: Effect) (es :: k).
Handling esSend e es =>
Env esSend
esSend)