module Effectful.Reader.Static
(
Reader
, runReader
, withReader
, ask
, asks
, local
) where
import Effectful
import Effectful.Dispatch.Static
data Reader r :: Effect
type instance DispatchOf (Reader r) = Static NoSideEffects
newtype instance StaticRep (Reader r) = Reader r
runReader
:: r
-> Eff (Reader r : es) a
-> Eff es a
runReader :: forall r (es :: [(Type -> Type) -> Type -> Type]) a.
r -> Eff (Reader r : es) a -> Eff es a
runReader r
r = forall (e :: (Type -> Type) -> Type -> Type)
(sideEffects :: SideEffects)
(es :: [(Type -> Type) -> Type -> Type]) a.
(DispatchOf e ~ 'Static sideEffects, MaybeIOE sideEffects es) =>
StaticRep e -> Eff (e : es) a -> Eff es a
evalStaticRep (forall r. r -> StaticRep (Reader r)
Reader r
r)
withReader
:: (r1 -> r2)
-> Eff (Reader r2 : es) a
-> Eff (Reader r1 : es) a
withReader :: forall r1 r2 (es :: [(Type -> Type) -> Type -> Type]) a.
(r1 -> r2) -> Eff (Reader r2 : es) a -> Eff (Reader r1 : es) a
withReader r1 -> r2
f Eff (Reader r2 : es) a
m = do
r1
r <- forall r (es :: [(Type -> Type) -> Type -> Type]).
(Reader r :> es) =>
Eff es r
ask
forall (es :: [(Type -> Type) -> Type -> Type]) a
(e :: (Type -> Type) -> Type -> Type).
Eff es a -> Eff (e : es) a
raise forall a b. (a -> b) -> a -> b
$ forall r (es :: [(Type -> Type) -> Type -> Type]) a.
r -> Eff (Reader r : es) a -> Eff es a
runReader (r1 -> r2
f r1
r) Eff (Reader r2 : es) a
m
ask :: Reader r :> es => Eff es r
ask :: forall r (es :: [(Type -> Type) -> Type -> Type]).
(Reader r :> es) =>
Eff es r
ask = do
Reader r
r <- forall (e :: (Type -> Type) -> Type -> Type)
(sideEffects :: SideEffects)
(es :: [(Type -> Type) -> Type -> Type]).
(DispatchOf e ~ 'Static sideEffects, e :> es) =>
Eff es (StaticRep e)
getStaticRep
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure r
r
asks
:: Reader r :> es
=> (r -> a)
-> Eff es a
asks :: forall r (es :: [(Type -> Type) -> Type -> Type]) a.
(Reader r :> es) =>
(r -> a) -> Eff es a
asks r -> a
f = r -> a
f forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall r (es :: [(Type -> Type) -> Type -> Type]).
(Reader r :> es) =>
Eff es r
ask
local
:: Reader r :> es
=> (r -> r)
-> Eff es a
-> Eff es a
local :: forall r (es :: [(Type -> Type) -> Type -> Type]) a.
(Reader r :> es) =>
(r -> r) -> Eff es a -> Eff es a
local r -> r
f = forall (e :: (Type -> Type) -> Type -> Type)
(sideEffects :: SideEffects)
(es :: [(Type -> Type) -> Type -> Type]) a.
(DispatchOf e ~ 'Static sideEffects, e :> es) =>
(StaticRep e -> StaticRep e) -> Eff es a -> Eff es a
localStaticRep forall a b. (a -> b) -> a -> b
$ \(Reader r
r) -> forall r. r -> StaticRep (Reader r)
Reader (r -> r
f r
r)