planet-mitchell-0.1.0: Planet Mitchell

Safe HaskellSafe
LanguageHaskell2010

Cont

Contents

Synopsis

Cont

type Cont r = ContT r Identity #

Continuation monad. Cont r a is a CPS ("continuation-passing style") computation that produces an intermediate result of type a within a CPS computation whose final result type is r.

The return function simply creates a continuation which passes the value on.

The >>= operator adds the bound function into the continuation chain.

cont :: ((a -> r) -> r) -> Cont r a #

Construct a continuation-passing computation from a function. (The inverse of runCont)

runCont #

Arguments

:: Cont r a

continuation computation (Cont).

-> (a -> r)

the final continuation, which produces the final result (often id).

-> r 

The result of running a CPS computation with a given final continuation. (The inverse of cont)

mapCont :: (r -> r) -> Cont r a -> Cont r a #

Apply a function to transform the result of a continuation-passing computation.

withCont :: ((b -> r) -> a -> r) -> Cont r a -> Cont r b #

Apply a function to transform the continuation passed to a CPS computation.

ContT

newtype ContT (r :: k) (m :: k -> *) a :: forall k. k -> (k -> *) -> * -> * #

The continuation monad transformer. Can be used to add continuation handling to any type constructor: the Monad instance and most of the operations do not require m to be a monad.

ContT is not a functor on the category of monads, and many operations cannot be lifted through it.

Constructors

ContT 

Fields

Instances
MonadReader r' m => MonadReader r' (ContT r m) 
Instance details

Defined in Control.Monad.Reader.Class

Methods

ask :: ContT r m r' #

local :: (r' -> r') -> ContT r m a -> ContT r m a #

reader :: (r' -> a) -> ContT r m a #

MonadState s m => MonadState s (ContT r m) 
Instance details

Defined in Control.Monad.State.Class

Methods

get :: ContT r m s #

put :: s -> ContT r m () #

state :: (s -> (a, s)) -> ContT r m a #

(Functor f, MonadFree f m) => MonadFree f (ContT r m) 
Instance details

Defined in Control.Monad.Free.Class

Methods

wrap :: f (ContT r m a) -> ContT r m a #

MonadBase b m => MonadBase b (ContT r m) 
Instance details

Defined in Control.Monad.Base

Methods

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

MonadTrans (ContT r) 
Instance details

Defined in Control.Monad.Trans.Cont

Methods

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

Monad (ContT r m) 
Instance details

Defined in Control.Monad.Trans.Cont

Methods

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

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

return :: a -> ContT r m a #

fail :: String -> ContT r m a #

Functor (ContT r m) 
Instance details

Defined in Control.Monad.Trans.Cont

Methods

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

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

MonadFail m => MonadFail (ContT r m) 
Instance details

Defined in Control.Monad.Trans.Cont

Methods

fail :: String -> ContT r m a #

Applicative (ContT r m) 
Instance details

Defined in Control.Monad.Trans.Cont

Methods

pure :: a -> ContT r m a #

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

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

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

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

MonadIO m => MonadIO (ContT r m) 
Instance details

Defined in Control.Monad.Trans.Cont

Methods

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

MonadThrow m => MonadThrow (ContT r m) 
Instance details

Defined in Control.Monad.Catch

Methods

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

PrimMonad m => PrimMonad (ContT r m)

Since: primitive-0.6.3.0

Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState (ContT r m) :: * #

Methods

primitive :: (State# (PrimState (ContT r m)) -> (#State# (PrimState (ContT r m)), a#)) -> ContT r m a #

Apply (ContT r m) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<.>) :: ContT r m (a -> b) -> ContT r m a -> ContT r m b #

(.>) :: ContT r m a -> ContT r m b -> ContT r m b #

(<.) :: ContT r m a -> ContT r m b -> ContT r m a #

liftF2 :: (a -> b -> c) -> ContT r m a -> ContT r m b -> ContT r m c #

MonadManaged m => MonadManaged (ContT r m) 
Instance details

Defined in Control.Monad.Managed

Methods

using :: Managed a -> ContT r m a #

MonadCont (ContT r m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> ContT r m b) -> ContT r m a) -> ContT r m a #

Pointed (ContT r m) 
Instance details

Defined in Data.Pointed

Methods

point :: a -> ContT r m a #

Bind (ContT r m) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

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

join :: ContT r m (ContT r m a) -> ContT r m a #

Wrapped (ContT r m a) 
Instance details

Defined in Control.Lens.Wrapped

Associated Types

type Unwrapped (ContT r m a) :: * #

Methods

_Wrapped' :: Iso' (ContT r m a) (Unwrapped (ContT r m a)) #

t ~ ContT r' m' a' => Rewrapped (ContT r m a) t 
Instance details

Defined in Control.Lens.Wrapped

type PrimState (ContT r m) 
Instance details

Defined in Control.Monad.Primitive

type PrimState (ContT r m) = PrimState m
type Unwrapped (ContT r m a) 
Instance details

Defined in Control.Lens.Wrapped

type Unwrapped (ContT r m a) = (a -> m r) -> m r

mapContT :: (m r -> m r) -> ContT r m a -> ContT r m a #

Apply a function to transform the result of a continuation-passing computation. This has a more restricted type than the map operations for other monad transformers, because ContT does not define a functor in the category of monads.

withContT :: ((b -> m r) -> a -> m r) -> ContT r m a -> ContT r m b #

Apply a function to transform the continuation passed to a CPS computation.

MonadCont

class Monad m => MonadCont (m :: * -> *) where #

Minimal complete definition

callCC

Methods

callCC :: ((a -> m b) -> m a) -> m a #

callCC (call-with-current-continuation) calls a function with the current continuation as its argument. Provides an escape continuation mechanism for use with Continuation monads. Escape continuations allow to abort the current computation and return a value immediately. They achieve a similar effect to throwError and catchError within an Error monad. Advantage of this function over calling return is that it makes the continuation explicit, allowing more flexibility and better control (see examples in Control.Monad.Cont).

The standard idiom used with callCC is to provide a lambda-expression to name the continuation. Then calling the named continuation anywhere within its scope will escape from the computation, even if it is many layers deep within nested computations.

Instances
MonadCont m => MonadCont (MaybeT m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> MaybeT m b) -> MaybeT m a) -> MaybeT m a #

(Functor m, MonadCont m) => MonadCont (Free m) 
Instance details

Defined in Control.Monad.Free

Methods

callCC :: ((a -> Free m b) -> Free m a) -> Free m a #

MonadCont m => MonadCont (ListT m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> ListT m b) -> ListT m a) -> ListT m a #

MonadCont m => MonadCont (IdentityT m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> IdentityT m b) -> IdentityT m a) -> IdentityT m a #

MonadCont m => MonadCont (ExceptT e m)

Since: mtl-2.2

Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> ExceptT e m b) -> ExceptT e m a) -> ExceptT e m a #

(Functor f, MonadCont m) => MonadCont (FreeT f m) 
Instance details

Defined in Control.Monad.Trans.Free

Methods

callCC :: ((a -> FreeT f m b) -> FreeT f m a) -> FreeT f m a #

(Error e, MonadCont m) => MonadCont (ErrorT e m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> ErrorT e m b) -> ErrorT e m a) -> ErrorT e m a #

(Monoid w, MonadCont m) => MonadCont (WriterT w m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> WriterT w m b) -> WriterT w m a) -> WriterT w m a #

MonadCont m => MonadCont (StateT s m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> StateT s m b) -> StateT s m a) -> StateT s m a #

MonadCont m => MonadCont (StateT s m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> StateT s m b) -> StateT s m a) -> StateT s m a #

(Monoid w, MonadCont m) => MonadCont (WriterT w m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> WriterT w m b) -> WriterT w m a) -> WriterT w m a #

MonadCont m => MonadCont (ReaderT r m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> ReaderT r m b) -> ReaderT r m a) -> ReaderT r m a #

(Stream s, MonadCont m) => MonadCont (ParsecT e s m) 
Instance details

Defined in Text.Megaparsec.Internal

Methods

callCC :: ((a -> ParsecT e s m b) -> ParsecT e s m a) -> ParsecT e s m a #

MonadCont (ContT r m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> ContT r m b) -> ContT r m a) -> ContT r m a #

(Monoid w, MonadCont m) => MonadCont (RWST r w s m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a #

(Monoid w, MonadCont m) => MonadCont (RWST r w s m) 
Instance details

Defined in Control.Monad.Cont.Class

Methods

callCC :: ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a #