cleff-0.3.4.0: Fast and concise extensible effects
Copyright(c) 2021 Xy Ren
LicenseBSD3
Maintainerxy.r@outlook.com
Stabilityunstable
Portabilitynon-portable (GHC only)
Safe HaskellNone
LanguageHaskell2010

Cleff.Internal.Env

Description

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

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 (HandlerPtrs), 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.

esSend :: Handling esSend e es => Env esSend Source #

Get the send-site Env.

empty :: Env '[] Source #

Create an empty Env with no address allocated.

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) \).

extend :: forall e es es'. Env es' -> Handler e es' -> Env es -> Env (e ': es) Source #

Add a new effect to the stack with its corresponding handler pointer. \( O(n) \).

update :: forall es es'. Env es' -> Env es -> Env es Source #

Use the state of LHS as a newer version for RHS. \( O(1) \).