Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Primitive API for statically dispatched effects.
This module exposes internal implementation details of the Eff
monad. Most of the time functions from Effectful.Dispatch.Static are
sufficient.
Warning: playing the so called "type tetris" with functions from this module is not enough. Their misuse might lead to data races or internal consistency check failures, so make sure you understand what you're doing.
Synopsis
- data Env (es :: [Effect])
- newtype Relinker :: (Effect -> Type) -> Effect -> Type where
- dummyRelinker :: Relinker rep e
- type family EffectRep (d :: Dispatch) :: Effect -> Type
- consEnv :: EffectRep (DispatchOf e) e -> Relinker (EffectRep (DispatchOf e)) e -> Env es -> IO (Env (e ': es))
- unconsEnv :: Env (e ': es) -> IO ()
- getEnv :: forall e es. e :> es => Env es -> IO (EffectRep (DispatchOf e) e)
- putEnv :: forall e es. e :> es => Env es -> EffectRep (DispatchOf e) e -> IO ()
- stateEnv :: forall e es a. e :> es => Env es -> (EffectRep (DispatchOf e) e -> IO (a, EffectRep (DispatchOf e) e)) -> IO a
- modifyEnv :: forall e es. e :> es => Env es -> (EffectRep (DispatchOf e) e -> IO (EffectRep (DispatchOf e) e)) -> IO ()
- emptyEnv :: IO (Env '[])
- cloneEnv :: Env es -> IO (Env es)
- restoreEnv :: Env es -> Env es -> IO ()
- sizeEnv :: Env es -> IO Int
- tailEnv :: Env (e ': es) -> IO (Env es)
The environment
data Env (es :: [Effect]) Source #
A strict (WHNF), thread local, mutable, extensible record indexed by types
of kind Effect
.
Warning: the environment is a mutable data structure and cannot be simultaneously used from multiple threads under any circumstances.
In order to pass it to a different thread, you need to perform a deep copy
with the cloneEnv
funtion.
Offers very good performance characteristics for most often performed operations:
Relinker
newtype Relinker :: (Effect -> Type) -> Effect -> Type where Source #
A function for relinking Env
objects stored in the handlers and/or making
a deep copy of the representation of the effect when cloning the environment.
dummyRelinker :: Relinker rep e Source #
A dummy Relinker
.
Representation of effects
type family EffectRep (d :: Dispatch) :: Effect -> Type Source #
Internal representations of effects.
Extending and shrinking
:: EffectRep (DispatchOf e) e | The representation of the effect. |
-> Relinker (EffectRep (DispatchOf e)) e | |
-> Env es | |
-> IO (Env (e ': es)) |
Extend the environment with a new data type.
unconsEnv :: Env (e ': es) -> IO () Source #
Shrink the environment by one data type.
Note: after calling this function e
from the input environment is no
longer usable.
Data retrieval and update
:: forall e es. e :> es | |
=> Env es | The environment. |
-> IO (EffectRep (DispatchOf e) e) |
Extract a specific data type from the environment.
:: forall e es. e :> es | |
=> Env es | The environment. |
-> EffectRep (DispatchOf e) e | |
-> IO () |
Replace the data type in the environment with a new value (in place).
:: forall e es a. e :> es | |
=> Env es | The environment. |
-> (EffectRep (DispatchOf e) e -> IO (a, EffectRep (DispatchOf e) e)) | |
-> IO a |
Modify the data type in the environment and return a value (in place).
:: forall e es. e :> es | |
=> Env es | The environment. |
-> (EffectRep (DispatchOf e) e -> IO (EffectRep (DispatchOf e) e)) | |
-> IO () |
Modify the data type in the environment (in place).
Utils
Restore the environment from its clone.
Since: 2.2.0.0