module Effectful.State.Static.Local
(
State
, runState
, evalState
, execState
, get
, gets
, put
, state
, modify
, stateM
, modifyM
) where
import Effectful
import Effectful.Dispatch.Static
data State s :: Effect
type instance DispatchOf (State s) = Static NoSideEffects
newtype instance StaticRep (State s) = State s
runState
:: s
-> Eff (State s : es) a
-> Eff es (a, s)
runState :: forall s (es :: [(Type -> Type) -> Type -> Type]) a.
s -> Eff (State s : es) a -> Eff es (a, s)
runState s
s0 Eff (State s : es) a
m = do
(a
a, State s
s) <- 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, StaticRep e)
runStaticRep (forall s. s -> StaticRep (State s)
State s
s0) Eff (State s : es) a
m
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (a
a, s
s)
evalState
:: s
-> Eff (State s : es) a
-> Eff es a
evalState :: forall s (es :: [(Type -> Type) -> Type -> Type]) a.
s -> Eff (State s : es) a -> Eff es a
evalState s
s = 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 s. s -> StaticRep (State s)
State s
s)
execState
:: s
-> Eff (State s : es) a
-> Eff es s
execState :: forall s (es :: [(Type -> Type) -> Type -> Type]) a.
s -> Eff (State s : es) a -> Eff es s
execState s
s0 Eff (State s : es) a
m = do
State s
s <- 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 (StaticRep e)
execStaticRep (forall s. s -> StaticRep (State s)
State s
s0) Eff (State s : es) a
m
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure s
s
get :: State s :> es => Eff es s
get :: forall s (es :: [(Type -> Type) -> Type -> Type]).
(State s :> es) =>
Eff es s
get = do
State s
s <- 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 s
s
gets
:: State s :> es
=> (s -> a)
-> Eff es a
gets :: forall s (es :: [(Type -> Type) -> Type -> Type]) a.
(State s :> es) =>
(s -> a) -> Eff es a
gets s -> a
f = s -> a
f forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (es :: [(Type -> Type) -> Type -> Type]).
(State s :> es) =>
Eff es s
get
put :: State s :> es => s -> Eff es ()
put :: forall s (es :: [(Type -> Type) -> Type -> Type]).
(State s :> es) =>
s -> Eff es ()
put s
s = forall (e :: (Type -> Type) -> Type -> Type)
(sideEffects :: SideEffects)
(es :: [(Type -> Type) -> Type -> Type]).
(DispatchOf e ~ 'Static sideEffects, e :> es) =>
StaticRep e -> Eff es ()
putStaticRep (forall s. s -> StaticRep (State s)
State s
s)
state
:: State s :> es
=> (s -> (a, s))
-> Eff es a
state :: forall s (es :: [(Type -> Type) -> Type -> Type]) a.
(State s :> es) =>
(s -> (a, s)) -> Eff es a
state s -> (a, s)
f = forall (e :: (Type -> Type) -> Type -> Type)
(sideEffects :: SideEffects)
(es :: [(Type -> Type) -> Type -> Type]) a.
(DispatchOf e ~ 'Static sideEffects, e :> es) =>
(StaticRep e -> (a, StaticRep e)) -> Eff es a
stateStaticRep forall a b. (a -> b) -> a -> b
$ \(State s
s0) -> let (a
a, s
s) = s -> (a, s)
f s
s0 in (a
a, forall s. s -> StaticRep (State s)
State s
s)
modify
:: State s :> es
=> (s -> s)
-> Eff es ()
modify :: forall s (es :: [(Type -> Type) -> Type -> Type]).
(State s :> es) =>
(s -> s) -> Eff es ()
modify s -> s
f = forall s (es :: [(Type -> Type) -> Type -> Type]) a.
(State s :> es) =>
(s -> (a, s)) -> Eff es a
state forall a b. (a -> b) -> a -> b
$ \s
s -> ((), s -> s
f s
s)
stateM
:: State s :> es
=> (s -> Eff es (a, s))
-> Eff es a
stateM :: forall s (es :: [(Type -> Type) -> Type -> Type]) a.
(State s :> es) =>
(s -> Eff es (a, s)) -> Eff es a
stateM s -> Eff es (a, s)
f = forall (e :: (Type -> Type) -> Type -> Type)
(sideEffects :: SideEffects)
(es :: [(Type -> Type) -> Type -> Type]) a.
(DispatchOf e ~ 'Static sideEffects, e :> es) =>
(StaticRep e -> Eff es (a, StaticRep e)) -> Eff es a
stateStaticRepM forall a b. (a -> b) -> a -> b
$ \(State s
s0) -> do
(a
a, s
s) <- s -> Eff es (a, s)
f s
s0
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (a
a, forall s. s -> StaticRep (State s)
State s
s)
modifyM
:: State s :> es
=> (s -> Eff es s)
-> Eff es ()
modifyM :: forall s (es :: [(Type -> Type) -> Type -> Type]).
(State s :> es) =>
(s -> Eff es s) -> Eff es ()
modifyM s -> Eff es s
f = forall s (es :: [(Type -> Type) -> Type -> Type]) a.
(State s :> es) =>
(s -> Eff es (a, s)) -> Eff es a
stateM (\s
s -> ((), ) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Eff es s
f s
s)