Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Cont m a where
- newtype Shift r m a where
- callCC :: Eff Cont m => ((forall b. a -> m b) -> m a) -> m a
- shift :: Eff (Shift r) m => ((a -> m r) -> m r) -> m a
- runCont :: forall a m p. (Carrier m, Threaders '[ContThreads] m p) => ContC a m a -> m a
- runContFast :: forall a m p. (Carrier m, Threaders '[ContFastThreads] m p) => ContFastC a m a -> m a
- runShift :: forall r m p. (Carrier m, Threaders '[ContThreads] m p) => ShiftC r m r -> m r
- runShiftFast :: forall r m p. (Carrier m, Threaders '[ContFastThreads] m p) => ShiftFastC r m r -> m r
- contToShift :: Eff (Shift r) m => ContToShiftC r m a -> m a
- type ContThreads = FreeThreads
- class (forall s. Threads (ContT s) p) => ContFastThreads p
- data ContC r m a
- data ContFastC (r :: *) m a
- data ShiftC r m a
- data ShiftFastC (r :: *) m a
- type ContToShiftC r = InterpretC (ContToShiftH r) Cont
Effects
newtype Shift r m a where Source #
An effect for non-abortive continuations of a program
that eventually produces a result of type r
.
This isn't quite as powerful as proper delimited continuations,
as this doesn't provide any equivalent of the reset
operator.
This can be useful as a helper effect.
Actions
callCC :: Eff Cont m => ((forall b. a -> m b) -> m a) -> m a Source #
Call with current continuation. The argument computation is provided
the continuation of the program at the point that callCC
was invoked.
If the continuation is executed, then control will immediately abort
and jump to the point callCC
was invoked, which will then return
the argument provided to the continuation.
The way higher-order actions interact with the continuation depends
on the interpretation of Cont
. In general, you cannot expect to interact
with the continuation in any meaningful way: for example, you should not
assume that you will be able to catch an exception thrown at some point in
the future of the computation by using catch
on the
continuation.
shift :: Eff (Shift r) m => ((a -> m r) -> m r) -> m a Source #
Non-abortive call with current continuation. The argument computation is
provided the continuation of the program at the point that shift
was invoked.
If the continuation is executed, then control will jump to the point shift
was invoked, which will then return the argument provided to the continuation.
Once the program finishes, and produces an r
, control will jump back
to where the continuation was executed, and return that r
.
From that point, you may decide whether or not to modify the final r
,
or invoke the continuation again with a different argument.
You can also use shift
to abort the execution of the program early
by simply not executing the provided continuation, and instead
provide the final r
directly.
The way higher-order actions interact with the continuation depends
on the interpretation of Shift
. In general, you cannot expect to interact
with the continuation in any meaningful way: for example, you should not
assume that you will be able to catch an exception thrown at some point in
the future of the computation by using catch
on the
continuation.
Interpretations
runContFast :: forall a m p. (Carrier m, Threaders '[ContFastThreads] m p) => ContFastC a m a -> m a Source #
Run a Cont
effect.
Compared to runCont
, this is quite a bit faster, but is significantly more
restrictive in what interpreters are used after it, since there are very
few primitive effects that the carrier for runContFast
is able to thread.
In fact, of all the primitive effects provided by this library, only
one satisfies ContFastThreads
: namely,
ReaderPrim
.
Derivs
(ContFastC
r m) =Cont
':Derivs
m
Prims
(ContFastC
r m) =Prims
m
runShiftFast :: forall r m p. (Carrier m, Threaders '[ContFastThreads] m p) => ShiftFastC r m r -> m r Source #
Run a
effect if the program returns Shift
rr
.
Compared to runCont
, this is quite a bit faster, but is significantly more
restrictive in what interpreters are used after it, since there are very
few primitive effects that the carrier for runContFast
is able to thread.
In fact, of all the primitive effects provided by this library, only
one satisfies ContFastThreads
: namely,
ReaderPrim
.
Derivs
(ShiftFastC
r m) =Shift
r ':Derivs
m
Prims
(ShiftFastC
r m) =Prims
m
contToShift :: Eff (Shift r) m => ContToShiftC r m a -> m a Source #
Threading constraints
type ContThreads = FreeThreads Source #
ContThreads
accepts the following primitive effects:
Regional
s
Optional
s
(whens
is a functor)Unravel
p
ListenPrim
s
(whens
is aMonoid
)ReaderPrim
i
class (forall s. Threads (ContT s) p) => ContFastThreads p Source #
ContFastThreads
accepts the following primitive effects:
Instances
(forall s. Threads (ContT s) p) => ContFastThreads p Source # | |
Defined in Control.Effect.Internal.Cont |
Carriers
Instances
MonadBase b m => MonadBase b (ContC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
MonadTrans (ContC s) Source # | |
Defined in Control.Effect.Internal.Cont | |
Monad (ContC r m) Source # | |
Functor (ContC r m) Source # | |
MonadFail m => MonadFail (ContC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
Applicative (ContC r m) Source # | |
MonadIO m => MonadIO (ContC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
MonadThrow m => MonadThrow (ContC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
MonadCatch m => MonadCatch (ContC r m) Source # | |
(Carrier m, Threads (FreeT (ContBase (m r))) (Prims m)) => Carrier (ContC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
type Derivs (ContC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
type Prims (ContC r m) Source # | |
Defined in Control.Effect.Internal.Cont |
data ContFastC (r :: *) m a Source #
Instances
Instances
MonadBase b m => MonadBase b (ShiftC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
MonadTrans (ShiftC s) Source # | |
Defined in Control.Effect.Internal.Cont | |
Monad (ShiftC r m) Source # | |
Functor (ShiftC r m) Source # | |
MonadFail m => MonadFail (ShiftC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
Applicative (ShiftC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
MonadIO m => MonadIO (ShiftC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
MonadThrow m => MonadThrow (ShiftC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
MonadCatch m => MonadCatch (ShiftC r m) Source # | |
(Carrier m, Threads (FreeT (ContBase (m r))) (Prims m)) => Carrier (ShiftC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
type Derivs (ShiftC r m) Source # | |
Defined in Control.Effect.Internal.Cont | |
type Prims (ShiftC r m) Source # | |
Defined in Control.Effect.Internal.Cont |
data ShiftFastC (r :: *) m a Source #
Instances
type ContToShiftC r = InterpretC (ContToShiftH r) Cont Source #