| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Effectful.Internal.Monad
Description
The Eff monad.
This module is intended for internal use only, and may change without warning in subsequent releases.
Synopsis
- data Eff (es :: [Effect]) a
- runPureEff :: Eff '[] a -> a
- unEff :: Eff es a -> Env es -> IO a
- unsafeEff :: (Env es -> IO a) -> Eff es a
- unsafeEff_ :: IO a -> Eff es a
- data Fail :: Effect where
- data IOE :: Effect
- runEff :: Eff '[IOE] a -> IO a
- data Prim :: Effect
- runPrim :: IOE :> es => Eff (Prim ': es) a -> Eff es a
- raise :: Eff es a -> Eff (e ': es) a
- subsume :: e :> es => Eff (e ': es) a -> Eff es a
- inject :: Subset xs es => Eff xs a -> Eff es a
- data UnliftStrategy
- data Persistence
- data Limit
- unliftStrategy :: IOE :> es => Eff es UnliftStrategy
- withUnliftStrategy :: IOE :> es => UnliftStrategy -> Eff es a -> Eff es a
- withEffToIO :: (HasCallStack, IOE :> es) => ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
- seqUnliftIO :: HasCallStack => Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
- concUnliftIO :: HasCallStack => Env es -> Persistence -> Limit -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
- type EffectHandler e es = forall a localEs. HasCallStack => LocalEnv localEs es -> e (Eff localEs) a -> Eff es a
- newtype LocalEnv (localEs :: [Effect]) (handlerEs :: [Effect]) = LocalEnv (Env localEs)
- data Handler :: Effect -> Type where
- Handler :: !(Env es) -> !(EffectHandler e es) -> Handler e
- relinkHandler :: Relinker Handler e
- runHandler :: DispatchOf e ~ Dynamic => Handler e -> Eff (e ': es) a -> Eff es a
- send :: (HasCallStack, DispatchOf e ~ Dynamic, e :> es) => e (Eff es) a -> Eff es a
- data family StaticRep (e :: Effect) :: Type
- type family MaybeIOE (sideEffects :: SideEffects) (es :: [Effect]) :: Constraint where ...
- runStaticRep :: (DispatchOf e ~ Static sideEffects, MaybeIOE sideEffects es) => StaticRep e -> Eff (e ': es) a -> Eff es (a, StaticRep e)
- evalStaticRep :: (DispatchOf e ~ Static sideEffects, MaybeIOE sideEffects es) => StaticRep e -> Eff (e ': es) a -> Eff es a
- execStaticRep :: (DispatchOf e ~ Static sideEffects, MaybeIOE sideEffects es) => StaticRep e -> Eff (e ': es) a -> Eff es (StaticRep e)
- getStaticRep :: (DispatchOf e ~ Static sideEffects, e :> es) => Eff es (StaticRep e)
- putStaticRep :: (DispatchOf e ~ Static sideEffects, e :> es) => StaticRep e -> Eff es ()
- stateStaticRep :: (DispatchOf e ~ Static sideEffects, e :> es) => (StaticRep e -> (a, StaticRep e)) -> Eff es a
- stateStaticRepM :: (DispatchOf e ~ Static sideEffects, e :> es) => (StaticRep e -> Eff es (a, StaticRep e)) -> Eff es a
- localStaticRep :: (DispatchOf e ~ Static sideEffects, e :> es) => (StaticRep e -> StaticRep e) -> Eff es a -> Eff es a
- consEnv :: EffectRep (DispatchOf e) e -> Relinker (EffectRep (DispatchOf e)) e -> Env es -> IO (Env (e ': es))
- 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 -> (a, EffectRep (DispatchOf e) e)) -> IO a
- modifyEnv :: forall e es. e :> es => Env es -> (EffectRep (DispatchOf e) e -> EffectRep (DispatchOf e) e) -> IO ()
The Eff monad
data Eff (es :: [Effect]) a Source #
The Eff monad provides the implementation of a computation that performs
an arbitrary set of effects. In , Eff es aes is a type-level list that
contains all the effects that the computation may perform. For example, a
computation that produces an Integer by consuming a String from the
global environment and acting upon a single mutable value of type Bool
would have the following type:
(ReaderString:>es,StateBool:>es) =>EffesInteger
Abstracting over the list of effects with (:>):
- Allows the computation to be used in functions that may perform other effects.
- Allows the effects to be handled in any order.
Instances
runPureEff :: Eff '[] a -> a Source #
Access to the internal representation
unsafeEff_ :: IO a -> Eff es a Source #
Fail
data Fail :: Effect where Source #
Instances
| type DispatchOf Fail Source # | |
Defined in Effectful.Internal.Monad | |
IO
Run arbitrary IO computations via MonadIO or MonadUnliftIO.
Note: it is not recommended to use this effect in application code as it is too liberal. Ideally, this is only used in handlers of more fine-grained effects.
Instances
| type DispatchOf IOE Source # | |
Defined in Effectful.Internal.Monad | |
| newtype StaticRep IOE Source # | |
Defined in Effectful.Internal.Monad | |
runEff :: Eff '[IOE] a -> IO a Source #
Run an Eff computation with side effects.
For running pure computations see runPureEff.
Prim
Provide the ability to perform primitive state-transformer actions.
Instances
| type DispatchOf Prim Source # | |
Defined in Effectful.Internal.Monad | |
| data StaticRep Prim Source # | |
Defined in Effectful.Internal.Monad | |
runPrim :: IOE :> es => Eff (Prim ': es) a -> Eff es a Source #
Run an Eff computation with primitive state-transformer actions.
Lifting
subsume :: e :> es => Eff (e ': es) a -> Eff es a Source #
Eliminate a duplicate effect from the top of the effect stack.
inject :: Subset xs es => Eff xs a -> Eff es a Source #
Allow for running an effect stack xs within es as long as xs is a
permutation (with possible duplicates) of a subset of es.
Generalizes raise and subsume.
Note: this function should be needed rarely, usually when you have to cross
API boundaries and monomorphic effect stacks are involved. Using monomorphic
stacks is discouraged (see Eff), but sometimes might be necessary due to
external constraints.
Unlifting
data UnliftStrategy Source #
The strategy to use when unlifting Eff computations via
withEffToIO, withRunInIO or the
localUnlift family.
Warning: unlifting functions should not be used outside of continuations that brought them into scope. The behavior when doing so is undefined.
Constructors
| SeqUnlift | The fastest strategy and a default setting for |
| ConcUnlift !Persistence !Limit | A strategy that makes it possible for the unlifting function to be called
in threads distinct from its creator. See |
Instances
data Persistence Source #
Persistence setting for the ConcUnlift strategy.
Different functions require different persistence strategies. Examples:
- Lifting
pooledMapConcurrentlyNfrom theunliftiolibrary requires theEphemeralstrategy as we don't want jobs to share environment changes made by previous jobs run in the same worker thread. - Lifting
forkIOWithUnmaskrequires thePersistentstrategy, otherwise the unmasking function would start with a fresh environment each time it's called.
Constructors
| Ephemeral | Don't persist the environment between calls to the unlifting function in threads distinct from its creator. |
| Persistent | Persist the environment between calls to the unlifting function within a particular thread. |
Instances
| Eq Persistence Source # | |
Defined in Effectful.Internal.Unlift | |
| Ord Persistence Source # | |
Defined in Effectful.Internal.Unlift Methods compare :: Persistence -> Persistence -> Ordering # (<) :: Persistence -> Persistence -> Bool # (<=) :: Persistence -> Persistence -> Bool # (>) :: Persistence -> Persistence -> Bool # (>=) :: Persistence -> Persistence -> Bool # max :: Persistence -> Persistence -> Persistence # min :: Persistence -> Persistence -> Persistence # | |
| Show Persistence Source # | |
Defined in Effectful.Internal.Unlift Methods showsPrec :: Int -> Persistence -> ShowS # show :: Persistence -> String # showList :: [Persistence] -> ShowS # | |
| Generic Persistence Source # | |
Defined in Effectful.Internal.Unlift Associated Types type Rep Persistence :: Type -> Type # | |
| type Rep Persistence Source # | |
Defined in Effectful.Internal.Unlift | |
Limit setting for the ConcUnlift strategy.
Constructors
| Limited !Int | Behavior dependent on the For For |
| Unlimited | Unlimited use of the unlifting function. |
Instances
| Eq Limit Source # | |
| Ord Limit Source # | |
| Show Limit Source # | |
| Generic Limit Source # | |
| type Rep Limit Source # | |
Defined in Effectful.Internal.Unlift type Rep Limit = D1 ('MetaData "Limit" "Effectful.Internal.Unlift" "effectful-core-1.0.0.0-4BpXn01Z327Fw2u2ibXHIX" 'False) (C1 ('MetaCons "Limited" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "Unlimited" 'PrefixI 'False) (U1 :: Type -> Type)) | |
unliftStrategy :: IOE :> es => Eff es UnliftStrategy Source #
Get the current UnliftStrategy.
withUnliftStrategy :: IOE :> es => UnliftStrategy -> Eff es a -> Eff es a Source #
Locally override the UnliftStrategy with the given value.
Arguments
| :: (HasCallStack, IOE :> es) | |
| => ((forall r. Eff es r -> IO r) -> IO a) | Continuation with the unlifting function in scope. Note: the strategy is reset to |
| -> Eff es a |
Create an unlifting function with the current UnliftStrategy.
This function is equivalent to withRunInIO, but has a
HasCallStack constraint for accurate stack traces in case an insufficiently
powerful UnliftStrategy is used and the unlifting function fails.
Low-level unlifts
Arguments
| :: HasCallStack | |
| => Env es | The environment. |
| -> ((forall r. Eff es r -> IO r) -> IO a) | Continuation with the unlifting function in scope. |
| -> IO a |
Create an unlifting function with the SeqUnlift strategy.
Arguments
| :: HasCallStack | |
| => Env es | The environment. |
| -> Persistence | |
| -> Limit | |
| -> ((forall r. Eff es r -> IO r) -> IO a) | Continuation with the unlifting function in scope. |
| -> IO a |
Create an unlifting function with the ConcUnlift strategy.
Dispatch
Dynamic dispatch
type EffectHandler e es Source #
Arguments
| = forall a localEs. HasCallStack | |
| => LocalEnv localEs es | Capture of the local environment for handling local |
| -> e (Eff localEs) a | The effect performed in the local environment. |
| -> Eff es a |
Type signature of the effect handler.
newtype LocalEnv (localEs :: [Effect]) (handlerEs :: [Effect]) Source #
data Handler :: Effect -> Type where Source #
An internal representation of dynamically dispatched effects, i.e. the effect handler bundled with its environment.
Constructors
| Handler :: !(Env es) -> !(EffectHandler e es) -> Handler e |
relinkHandler :: Relinker Handler e Source #
runHandler :: DispatchOf e ~ Dynamic => Handler e -> Eff (e ': es) a -> Eff es a Source #
Run a dynamically dispatched effect with the given handler.
Arguments
| :: (HasCallStack, DispatchOf e ~ Dynamic, e :> es) | |
| => e (Eff es) a | The effect. |
| -> Eff es a |
Send an operation of the given effect to its handler for execution.
Static dispatch
data family StaticRep (e :: Effect) :: Type Source #
Internal representations of statically dispatched effects.
Instances
| data StaticRep Prim Source # | |
Defined in Effectful.Internal.Monad | |
| newtype StaticRep IOE Source # | |
Defined in Effectful.Internal.Monad | |
| newtype StaticRep (Error e) Source # | |
Defined in Effectful.Error.Static | |
| newtype StaticRep (Reader r) Source # | |
Defined in Effectful.Reader.Static | |
| newtype StaticRep (State s) Source # | |
Defined in Effectful.State.Static.Local | |
| newtype StaticRep (State s) Source # | |
Defined in Effectful.State.Static.Shared | |
| newtype StaticRep (Writer w) Source # | |
Defined in Effectful.Writer.Static.Local | |
| newtype StaticRep (Writer w) Source # | |
Defined in Effectful.Writer.Static.Shared | |
type family MaybeIOE (sideEffects :: SideEffects) (es :: [Effect]) :: Constraint where ... Source #
Require the IOE effect for running statically dispatched effects whose
operations perform side effects.
Equations
| MaybeIOE NoSideEffects _ = () | |
| MaybeIOE WithSideEffects es = IOE :> es |
Arguments
| :: (DispatchOf e ~ Static sideEffects, MaybeIOE sideEffects es) | |
| => StaticRep e | The initial representation. |
| -> Eff (e ': es) a | |
| -> Eff es (a, StaticRep e) |
Run a statically dispatched effect with the given initial representation and return the final value along with the final representation.
Arguments
| :: (DispatchOf e ~ Static sideEffects, MaybeIOE sideEffects es) | |
| => StaticRep e | The initial representation. |
| -> Eff (e ': es) a | |
| -> Eff es a |
Run a statically dispatched effect with the given initial representation and return the final value, discarding the final representation.
Arguments
| :: (DispatchOf e ~ Static sideEffects, MaybeIOE sideEffects es) | |
| => StaticRep e | The initial representation. |
| -> Eff (e ': es) a | |
| -> Eff es (StaticRep e) |
Run a statically dispatched effect with the given initial representation and return the final representation, discarding the final value.
getStaticRep :: (DispatchOf e ~ Static sideEffects, e :> es) => Eff es (StaticRep e) Source #
Fetch the current representation of the effect.
putStaticRep :: (DispatchOf e ~ Static sideEffects, e :> es) => StaticRep e -> Eff es () Source #
Set the current representation of the effect to the given value.
Arguments
| :: (DispatchOf e ~ Static sideEffects, e :> es) | |
| => (StaticRep e -> (a, StaticRep e)) | The function to modify the representation. |
| -> Eff es a |
Apply the function to the current representation of the effect and return a value.
Arguments
| :: (DispatchOf e ~ Static sideEffects, e :> es) | |
| => (StaticRep e -> Eff es (a, StaticRep e)) | The function to modify the representation. |
| -> Eff es a |
Apply the monadic function to the current representation of the effect and return a value.
Arguments
| :: (DispatchOf e ~ Static sideEffects, e :> es) | |
| => (StaticRep e -> StaticRep e) | The function to temporarily modify the representation. |
| -> Eff es a | |
| -> Eff es a |
Execute a computation with a temporarily modified representation of the effect.
Primitive operations
Arguments
| :: 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 (in place).
Arguments
| :: forall e es. e :> es | |
| => Env es | The environment. |
| -> IO (EffectRep (DispatchOf e) e) |
Extract a specific data type from the environment.
Arguments
| :: 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).
Arguments
| :: forall e es a. e :> es | |
| => Env es | The environment. |
| -> (EffectRep (DispatchOf e) e -> (a, EffectRep (DispatchOf e) e)) | |
| -> IO a |
Modify the data type in the environment (in place) and return a value.
Arguments
| :: forall e es. e :> es | |
| => Env es | The environment. |
| -> (EffectRep (DispatchOf e) e -> EffectRep (DispatchOf e) e) | |
| -> IO () |
Modify the data type in the environment (in place).