in-other-words-0.1.0.0: A higher-order effect system where the sky's the limit

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Cont

Contents

Synopsis

Effects

newtype Cont m a where Source #

An effect for abortive continuations.

Constructors

CallCC :: ((forall b. a -> m b) -> m a) -> Cont m a 

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.

Constructors

Shift :: ((a -> m r) -> m r) -> Shift r m a 

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

runCont :: forall a m p. (Carrier m, Threaders '[ContThreads] m p) => ContC a m a -> m a Source #

Run a Cont effect.

Derivs (ContC r m) = Cont ': Derivs m
Prims  (ContC r m) = Prims m

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

runShift :: forall r m p. (Carrier m, Threaders '[ContThreads] m p) => ShiftC r m r -> m r Source #

Run a Shift r effect if the program returns r.

Derivs (ShiftC r m) = Shift r ': Derivs m
Prims  (ShiftC r m) = Prims m

runShiftFast :: forall r m p. (Carrier m, Threaders '[ContFastThreads] m p) => ShiftFastC r m r -> m r Source #

Run a Shift r effect if the program returns r.

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 #

Transform a Cont effect into a Shift r effect.

Threading constraints

type ContThreads = FreeThreads Source #

ContThreads accepts the following primitive effects:

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 # 
Instance details

Defined in Control.Effect.Internal.Cont

Carriers

data ContC r m a Source #

Instances
MonadBase b m => MonadBase b (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

liftBase :: b α -> ContC r m α #

MonadTrans (ContC s) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

lift :: Monad m => m a -> ContC s m a #

Monad (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

(>>=) :: ContC r m a -> (a -> ContC r m b) -> ContC r m b #

(>>) :: ContC r m a -> ContC r m b -> ContC r m b #

return :: a -> ContC r m a #

fail :: String -> ContC r m a #

Functor (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

fmap :: (a -> b) -> ContC r m a -> ContC r m b #

(<$) :: a -> ContC r m b -> ContC r m a #

MonadFail m => MonadFail (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

fail :: String -> ContC r m a #

Applicative (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

pure :: a -> ContC r m a #

(<*>) :: ContC r m (a -> b) -> ContC r m a -> ContC r m b #

liftA2 :: (a -> b -> c) -> ContC r m a -> ContC r m b -> ContC r m c #

(*>) :: ContC r m a -> ContC r m b -> ContC r m b #

(<*) :: ContC r m a -> ContC r m b -> ContC r m a #

MonadIO m => MonadIO (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

liftIO :: IO a -> ContC r m a #

MonadThrow m => MonadThrow (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

throwM :: Exception e => e -> ContC r m a #

MonadCatch m => MonadCatch (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

catch :: Exception e => ContC r m a -> (e -> ContC r m a) -> ContC r m a #

(Carrier m, Threads (FreeT (ContBase (m r))) (Prims m)) => Carrier (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Associated Types

type Derivs (ContC r m) :: [Effect] Source #

type Prims (ContC r m) :: [Effect] Source #

Methods

algPrims :: Algebra' (Prims (ContC r m)) (ContC r m) a Source #

reformulate :: Monad z => Reformulation' (Derivs (ContC r m)) (Prims (ContC r m)) (ContC r m) z a Source #

algDerivs :: Algebra' (Derivs (ContC r m)) (ContC r m) a Source #

type Derivs (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

type Derivs (ContC r m) = Cont ': Derivs m
type Prims (ContC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

type Prims (ContC r m) = Prims m

data ContFastC (r :: *) m a Source #

Instances
MonadBase b m => MonadBase b (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

liftBase :: b α -> ContFastC r m α #

MonadTrans (ContFastC r) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

lift :: Monad m => m a -> ContFastC r m a #

Monad (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

(>>=) :: ContFastC r m a -> (a -> ContFastC r m b) -> ContFastC r m b #

(>>) :: ContFastC r m a -> ContFastC r m b -> ContFastC r m b #

return :: a -> ContFastC r m a #

fail :: String -> ContFastC r m a #

Functor (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

fmap :: (a -> b) -> ContFastC r m a -> ContFastC r m b #

(<$) :: a -> ContFastC r m b -> ContFastC r m a #

MonadFail m => MonadFail (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

fail :: String -> ContFastC r m a #

Applicative (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

pure :: a -> ContFastC r m a #

(<*>) :: ContFastC r m (a -> b) -> ContFastC r m a -> ContFastC r m b #

liftA2 :: (a -> b -> c) -> ContFastC r m a -> ContFastC r m b -> ContFastC r m c #

(*>) :: ContFastC r m a -> ContFastC r m b -> ContFastC r m b #

(<*) :: ContFastC r m a -> ContFastC r m b -> ContFastC r m a #

MonadIO m => MonadIO (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

liftIO :: IO a -> ContFastC r m a #

(Carrier m, Threads (ContT r) (Prims m)) => Carrier (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Associated Types

type Derivs (ContFastC r m) :: [Effect] Source #

type Prims (ContFastC r m) :: [Effect] Source #

type Derivs (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

type Derivs (ContFastC r m) = Cont ': Derivs m
type Prims (ContFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

type Prims (ContFastC r m) = Prims m

data ShiftC r m a Source #

Instances
MonadBase b m => MonadBase b (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

liftBase :: b α -> ShiftC r m α #

MonadTrans (ShiftC s) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

lift :: Monad m => m a -> ShiftC s m a #

Monad (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

(>>=) :: ShiftC r m a -> (a -> ShiftC r m b) -> ShiftC r m b #

(>>) :: ShiftC r m a -> ShiftC r m b -> ShiftC r m b #

return :: a -> ShiftC r m a #

fail :: String -> ShiftC r m a #

Functor (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

fmap :: (a -> b) -> ShiftC r m a -> ShiftC r m b #

(<$) :: a -> ShiftC r m b -> ShiftC r m a #

MonadFail m => MonadFail (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

fail :: String -> ShiftC r m a #

Applicative (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

pure :: a -> ShiftC r m a #

(<*>) :: ShiftC r m (a -> b) -> ShiftC r m a -> ShiftC r m b #

liftA2 :: (a -> b -> c) -> ShiftC r m a -> ShiftC r m b -> ShiftC r m c #

(*>) :: ShiftC r m a -> ShiftC r m b -> ShiftC r m b #

(<*) :: ShiftC r m a -> ShiftC r m b -> ShiftC r m a #

MonadIO m => MonadIO (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

liftIO :: IO a -> ShiftC r m a #

MonadThrow m => MonadThrow (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

throwM :: Exception e => e -> ShiftC r m a #

MonadCatch m => MonadCatch (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

catch :: Exception e => ShiftC r m a -> (e -> ShiftC r m a) -> ShiftC r m a #

(Carrier m, Threads (FreeT (ContBase (m r))) (Prims m)) => Carrier (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Associated Types

type Derivs (ShiftC r m) :: [Effect] Source #

type Prims (ShiftC r m) :: [Effect] Source #

Methods

algPrims :: Algebra' (Prims (ShiftC r m)) (ShiftC r m) a Source #

reformulate :: Monad z => Reformulation' (Derivs (ShiftC r m)) (Prims (ShiftC r m)) (ShiftC r m) z a Source #

algDerivs :: Algebra' (Derivs (ShiftC r m)) (ShiftC r m) a Source #

type Derivs (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

type Derivs (ShiftC r m) = Shift r ': Derivs m
type Prims (ShiftC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

type Prims (ShiftC r m) = Prims m

data ShiftFastC (r :: *) m a Source #

Instances
MonadBase b m => MonadBase b (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

liftBase :: b α -> ShiftFastC r m α #

MonadTrans (ShiftFastC r) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

lift :: Monad m => m a -> ShiftFastC r m a #

Monad (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

(>>=) :: ShiftFastC r m a -> (a -> ShiftFastC r m b) -> ShiftFastC r m b #

(>>) :: ShiftFastC r m a -> ShiftFastC r m b -> ShiftFastC r m b #

return :: a -> ShiftFastC r m a #

fail :: String -> ShiftFastC r m a #

Functor (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

fmap :: (a -> b) -> ShiftFastC r m a -> ShiftFastC r m b #

(<$) :: a -> ShiftFastC r m b -> ShiftFastC r m a #

MonadFail m => MonadFail (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

fail :: String -> ShiftFastC r m a #

Applicative (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

pure :: a -> ShiftFastC r m a #

(<*>) :: ShiftFastC r m (a -> b) -> ShiftFastC r m a -> ShiftFastC r m b #

liftA2 :: (a -> b -> c) -> ShiftFastC r m a -> ShiftFastC r m b -> ShiftFastC r m c #

(*>) :: ShiftFastC r m a -> ShiftFastC r m b -> ShiftFastC r m b #

(<*) :: ShiftFastC r m a -> ShiftFastC r m b -> ShiftFastC r m a #

MonadIO m => MonadIO (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Methods

liftIO :: IO a -> ShiftFastC r m a #

(Carrier m, Threads (ContT r) (Prims m)) => Carrier (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

Associated Types

type Derivs (ShiftFastC r m) :: [Effect] Source #

type Prims (ShiftFastC r m) :: [Effect] Source #

type Derivs (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

type Derivs (ShiftFastC r m) = Shift r ': Derivs m
type Prims (ShiftFastC r m) Source # 
Instance details

Defined in Control.Effect.Internal.Cont

type Prims (ShiftFastC r m) = Prims m

type ContToShiftC r = InterpretC (ContToShiftH r) Cont Source #