polysemy-zoo-0.7.0.2: Experimental, user-contributed effects and interpreters for polysemy
Safe HaskellNone
LanguageHaskell2010

Polysemy.Shift.Internal

Synopsis

Documentation

data Shift ref s m a where Source #

An effect for delimited continuations, formulated algebraically through a variant of the 'Polysemy.Cont.Jump/Subst formulation of abortive continuations.

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

Constructors

Trap :: (ref a -> m s) -> Shift ref s m a 
Invoke :: ref a -> a -> Shift ref s m s 
Abort :: s -> Shift ref s m a 
Reset :: m s -> Shift ref s m s 
Reset' :: m s -> Shift ref s m (Maybe s) 

Instances

Instances details
type DefiningModule Shift Source # 
Instance details

Defined in Polysemy.Shift.Internal

type DefiningModule Shift = "Polysemy.Shift.Internal"

trap :: forall ref s a r. Member (Shift ref s) r => (ref 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. Unlike subst, control will never return to the current continuation unless the prompt is invoked via release.

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

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

Any effectful state of effects which have been run before the interpreter for Shift will be embedded in the return value, and therefore the invocation won't have any apparent effects unless these are interpreted in the final monad.

Any higher-order actions will also not interact with the continuation in any meaningful way; i.e. local or censor does not affect it, catch will fail to catch any of its exceptions, and listen will always return mempty.

The provided continuation may fail locally in its subcontinuations. It may sometimes become necessary to handle such cases. To do so, use 'reset'' together with release.

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

Aborts the current continuation with a result.

reset :: forall ref s r. Member (Shift ref s) r => Sem r s -> Sem r s Source #

Delimits any continuations and calls to abort.

reset' :: forall ref s r. Member (Shift ref s) r => Sem r s -> Sem r (Maybe s) Source #

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

runShiftWeaving :: Monad m => (forall x. (x -> m (Maybe s)) -> Sem r x -> m (Maybe s)) -> Weaving (Shift (Ref m (Maybe s)) s) (Sem r) a -> ContT (Maybe s) m a Source #