0 | module Control.Effect.State
2 | import Control.EffectAlgebra
3 | import Control.HigherOrder
5 | import Control.Monad.State
7 | import public Control.Effect.Reader
8 | import public Control.Effect.Writer
12 | StateE : Type -> (Type -> Type) -> (Type -> Type)
13 | StateE s = ReaderE s :+: WriterE s
16 | Inj (StateE s) sig => Inj (ReaderE s) sig where
17 | inj = inj {sub = StateE s, sup = sig} . Inl
20 | Inj (StateE s) sig => Inj (WriterE s) sig where
21 | inj = inj {sub = StateE s, sup = sig} . Inr
33 | [State] Algebra sig m => Algebra (StateE s :+: sig) (StateT s m) where
34 | alg ctxx hdl (Inl (Inl Ask)) =
35 | ST $
\s => pure {f = m} (s, (s <$ ctxx))
36 | alg ctxx hdl (Inl (Inr (Tell s))) =
37 | ST $
\_ => pure {f = m} (s, ctxx)
38 | alg ctxx hdl (Inr x) = ST $
\r => do
40 | {f = Functor.Compose}
44 | h : Handler ((s,) . ctx) n m
47 | {ctx1 = (s,), ctx2 = ctx}
49 | {m = StateT s m} {n = m} (uncurry runStateT) hdl
52 | HintState : Algebra sig m => Algebra (StateE s :+: sig) (StateT s m)