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.Cont

  • 4 types
  • 8 values

Effect

1 declaration
datadata Cont (ref :: Type -> Type) (m :: k -> Type) (a :: k) where
#

An effect for abortive continuations.

Formulated à la Tom Schrijvers et al. "Monad Transformers and Modular Algebraic Effects: What Binds Them Together" (2016). http://www.cs.kuleuven.be/publicaties/rapporten/cw/CW699.pdf

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

Constructors

  • Jump :: ref a1 -> a1 -> Cont ref m a
  • Subst :: (ref a1 -> m a) -> (a1 -> m a) -> Cont ref m a

Actions

3 declarations
valuejump :: Member (Cont ref) r => ref a -> a -> Sem r b
#

Provide an answer to a prompt, jumping to its reified continuation, and aborting the current continuation.

Using jump will rollback all effectful state back to the point where the prompt was created, unless such state is interpreted in terms of the final monad, or the associated interpreter of the effectful state is run after runContUnsafe, which may be done if the effect isn't higher-order.

Higher-order effects do not interact with the continuation in any meaningful way; i.e. local or censor does not affect it, and catch will fail to catch any of its exceptions. The only exception to this is if you interpret such effects and Cont in terms of the final monad, and the final monad can perform such interactions in a meaningful manner.

valuesubst
  1. :: Member (Cont ref) r
  2. => ref a -> Sem r b
  3. -> a -> Sem r b
  4. -> Sem r b
#

Reifies the current continuation in the form of a prompt, and passes it to the first argument. If the prompt becomes invoked via jump, then the second argument will be run before the reified continuation, and otherwise will not be called at all.

valuecallCC
  1. :: Member (Cont ref) r
  2. => (forall b. a -> Sem r b) -> Sem r a
  3. -> Sem r a
#

Call with current continuation. Executing the provided continuation will abort execution.

Using the provided continuation will rollback all local effectful state back to the point where callCC was invoked.

Higher-order effects do not interact with the continuation in any meaningful way; i.e. local or censor does not affect it, and catch will fail to catch any of its exceptions. The only exception to this is if you interpret such effects and Cont in terms of the final monad, and the final monad can perform such interactions in a meaningful manner.

Interpretations

3 declarations

Experimental Interpretations

1 declaration
valuerunContViaFresh
  1. :: (Member (Fresh uniq) r, Eq uniq)
  2. => Sem (Cont (ViaFreshRef uniq) ': r) a
  3. -> Sem r (Maybe a)
#

A highly experimental Cont interpreter that functions through a combination of Error and Fresh. This may be used safely anywhere in the effect stack.

runContViaFresh is still under development. You're encouraged to experiment with it, but don't rely on it. For best results, use runContViaFresh as the first interpreter you run, such that all other effects are global in respect to it.

This interpreter may return Nothing if the control flow becomes split into separate, inconsistent parts, such that backtracking fails when trying to invoke continuations. For example, if you reify a continuation inside an async:ed thread, and then have that thread return the reified continuation back to the main thread through an await, then runContViaFresh will return Nothing upon executing the continuation in the main thread.

Unsafe Interpretations

1 declaration
valuerunContUnsafe :: Sem (Cont (Ref (Sem r) a) ': r) a -> Sem r a
#

Runs a Cont effect by providing pure as the final continuation.

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 runContUnsafe only after running all interpreters for your higher-order effects.

Note that Final is a higher-order effect, and thus runContUnsafe can't safely be used together with runFinal.

Prompt types

3 declarations
newtypenewtype Ref (m :: k -> Type) (s :: k) a
#

Constructors

Instances1Contravariant
  • Contravariant (Ref m s)Defined in polysemy-zoo-0.8.2.0 · Polysemy.Cont.Internal