Copyright | (c) 2021 Xy Ren |
---|---|
License | BSD3 |
Maintainer | xy.r@outlook.com |
Stability | unstable |
Portability | non-portable (GHC only) |
Safe Haskell | None |
Language | Haskell2010 |
Operations on the effect environment type Env
. These operations are more flexible than the public API; you may
want to use these in conjunction with the effect stack manipulation operations in Cleff.Internal.Stack.
This is an internal module and its API may change even between minor versions. Therefore you should be extra careful if you're to depend on this module.
Synopsis
- data Env (es :: [Effect])
- class Handling esSend e es | esSend -> e es
- type Handler e es = forall esSend. Handling esSend e es => e (Eff esSend) ~> Eff es
- esSend :: Handling esSend e es => Env esSend
- empty :: Env '[]
- read :: forall e es. e :> es => Env es -> forall es'. e (Eff es') ~> Eff es'
- adjust :: forall es' es. (Stack es -> Stack es') -> Env es -> Env es'
- overwriteLocal :: forall e es es'. e :> es => Env es' -> Handler e es' -> Env es -> Env es
- overwriteGlobal :: forall e es es'. e :> es => Env es' -> Handler e es' -> Env es -> Env es
- overwriteSelfGlobal :: forall e es es' esSend. Handling esSend e es => Env es' -> Handler e es' -> Env esSend -> Env esSend
- extend :: forall e es es'. Env es' -> Handler e es' -> Env es -> Env (e ': es)
- update :: forall es es'. Env es' -> Env es -> Env es
Documentation
data Env (es :: [Effect]) Source #
The effect environment that corresponds effects in the stack to their respective handlers. This
structure simulates memory: handlers are retrieved via pointers (HandlerPtr
s), and for each effect in the stack
we can either change what pointer it uses or change the handler the pointer points to. The former is used for global
effect interpretation (reinterpretN
) and the latter for local interpretation (toEffWith
) in order to
retain correct HO semantics. For more details on this see https://github.com/re-xyr/cleff/issues/5.
class Handling esSend e es | esSend -> e es Source #
The typeclass that denotes a handler scope, handling effect e
sent from the effect stack esSend
in the
effect stack es
.
You should not define instances for this typeclass whatsoever.
type Handler e es = forall esSend. Handling esSend e es => e (Eff esSend) ~> Eff es Source #
The type of an effect handler, which is a function that transforms an effect e
from an arbitrary effect stack
into computations in the effect stack es
.
read :: forall e es. e :> es => Env es -> forall es'. e (Eff es') ~> Eff es' Source #
Read the handler a pointer points to. \( O(1) \).
adjust :: forall es' es. (Stack es -> Stack es') -> Env es -> Env es' Source #
Adjust the effect stack via an function over Stack
.
overwriteLocal :: forall e es es'. e :> es => Env es' -> Handler e es' -> Env es -> Env es Source #
Replace the handler pointer of an effect in the stack. \( O(n) \).
overwriteGlobal :: forall e es es'. e :> es => Env es' -> Handler e es' -> Env es -> Env es Source #
Replace the handler a pointer points to. \( O(1) \).
overwriteSelfGlobal :: forall e es es' esSend. Handling esSend e es => Env es' -> Handler e es' -> Env esSend -> Env esSend Source #
Replace the handler a pointer points to. \( O(1) \).