HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulepolysemy-zoo-0.8.2.0Haskell2010

Polysemy.Shift

  • 1 type
  • 19 values

Effect

1 declaration
datadata Shift (ref :: Type -> Type) s (m :: Type -> Type) a where
#

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

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

Constructors

Actions

6 declarations
valuetrap :: Member (Shift ref s) r => (ref a -> Sem r s) -> Sem r a
#

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.

valueinvoke :: Member (Shift ref s) r => ref a -> a -> Sem r s
#

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.

valueabort :: Member (Shift ref s) r => s -> Sem r a
#

Aborts the current continuation with a result.

valuereset' :: Member (Shift ref s) r => Sem r s -> Sem r (Maybe s)
#

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

valueshift :: Member (Shift ref s) r => ((a -> Sem r s) -> Sem r s) -> Sem r a
#

A variant of callCC. Executing the provided continuation will not abort execution.

Any effectful state of effects which have been run before the interpreter for Shift will be embedded in the return value of the continuation, and therefore the continuation won't have any apparent effects unless these effects 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, in which case such failure may be detected by using 'reset'' together with the provided continuation.

Interpretations

9 declarations

Unsafe Interpretations

4 declarations
valuerunShiftUnsafe
  1. :: Sem (Shift (Ref (Sem r) (Maybe a)) a ': r) a
  2. -> Sem r (Maybe a)
#

Runs a Shift 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.

Beware: This interpreter will invalidate all higher-order effects of any interpreter run after it; i.e. local and censor will be no-ops, catch will fail to catch exceptions, and listen will always return mempty.

You should therefore use runShiftUnsafe after running all interpreters for your higher-order effects.

valuerunShiftWithCUnsafe
  1. :: a -> Sem r (Maybe s)
  2. -> Sem (Shift (Ref (Sem r) (Maybe s)) s ': r) a
  3. -> Sem r (Maybe s)
#

Runs a Shift 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.

Beware: This interpreter will invalidate all higher-order effects of any interpreter run after it; i.e. local and censor will be no-ops, catch will fail to catch exceptions, and listen will always return mempty.

You should therefore use runShiftWithCUnsafe after running all interpreters for your higher-order effects.

valuerunContShiftUnsafe
  1. :: Sem (Cont (Ref (Sem r) (Maybe a)) ': Shift (Ref (Sem r) (Maybe a)) a ': r) a
  2. -> Sem r (Maybe a)
#

Runs a Cont and a Shift effect simultaneously 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.

Beware: This interpreter will invalidate all higher-order effects of any interpreter run after it; i.e. local and censor will be no-ops, catch will fail to catch exceptions, and listen will always return mempty.

You should therefore use runContShiftUnsafe after running all interpreters for your higher-order effects.

valuerunContShiftWithCUnsafe
  1. :: a -> Sem r (Maybe s)
  2. -> Sem (Cont (Ref (Sem r) (Maybe s)) ': Shift (Ref (Sem r) (Maybe s)) s ': r) a
  3. -> Sem r (Maybe s)
#

Runs a Cont and a Shift effect simultaneously 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.

Beware: This interpreter will invalidate all higher-order effects of any interpreter run after it; i.e. local and censor will be no-ops, catch will fail to catch exceptions, and listen will always return mempty.

You should therefore use runContShiftWithCUnsafe after running all interpreters for your higher-order effects.