polysemy-zoo-0.8.1.0: Experimental, user-contributed effects and interpreters for polysemy
Safe HaskellTrustworthy
LanguageHaskell2010

Polysemy.Capture

Synopsis

Effect

data Capture ref m a where Source #

A less powerful variant of Shift that may always be interpreted safely. Unlike Shift, continuations can't leave the scope in which they are provided.

Note: Any computation used in a higher-order effect will be delimited.

Activating polysemy-plugin is highly recommended when using this effect in order to avoid ambiguous types.

Constructors

Reify :: (forall s. ref s a -> m s) -> Capture ref m a 
Reflect :: ref s a -> a -> Capture ref m s 
Delimit :: m a -> Capture ref m a 
Delimit' :: m a -> Capture ref m (Maybe a) 

Actions

reify :: forall ref a r. Member (Capture ref) r => (forall s. ref s a -> Sem r s) -> Sem r a Source #

Reifies the current continuation in the form of a prompt, and passes it to the first argument.

reflect :: forall ref s a r. Member (Capture ref) r => ref s a -> a -> Sem r s Source #

Provide an answer to a prompt, jumping to its reified continuation. This will not abort the current continuation, and the reified computation will return its final result when finished.

The provided continuation may fail locally in its subcontinuations. It may sometimes become necessary to handle such cases. To do so, use delimit' together with reflect (the reified continuation is already delimited).

delimit :: forall ref a r. Member (Capture ref) r => Sem r a -> Sem r a Source #

Delimits any continuations

delimit' :: forall ref a r. Member (Capture ref) r => Sem r a -> Sem r (Maybe a) Source #

Delimits any continuations, and detects if any subcontinuation has failed locally.

capture :: forall ref r a. Member (Capture ref) r => (forall s. (a -> Sem r s) -> Sem r s) -> Sem r a Source #

A restricted version of shift. Executing the provided continuation will not abort execution.

The provided continuation may fail locally in its subcontinuations. It may sometimes become necessary to handle such cases, in which case such failure may be detected by using delimit' together with the provided continuation (the provided continuation is already delimited).

Interpretations

runCapture :: Sem (Capture (Ref (Sem r)) ': r) a -> Sem r (Maybe a) Source #

Runs a Capture effect by providing pure . Just as the final continuation.

The final return type is wrapped in a Maybe due to the fact that any continuation may fail locally.

runCaptureWithC :: (a -> Sem r (Maybe s)) -> Sem (Capture (Ref (Sem r)) ': r) a -> Sem r (Maybe s) Source #

Runs a Capture effect by explicitly providing a final continuation.

The final return type is wrapped in a Maybe due to the fact that any continuation may fail locally.

Prompt types

newtype Ref m s a Source #

Constructors

Ref 

Fields

Instances

Instances details
Contravariant (Ref m s) Source # 
Instance details

Defined in Polysemy.Cont.Internal

Methods

contramap :: (a -> b) -> Ref m s b -> Ref m s a #

(>$) :: b -> Ref m s b -> Ref m s a #