constrained-monads-0.2.0.0: Typeclasses and instances for monads with constraints.

Safe HaskellNone
LanguageHaskell2010

Control.Monad.Constrained.Cont

Description

This module is a duplication of the Control.Monad.Cont module, from the mtl.

Synopsis

Documentation

class Monad m => MonadCont m where Source #

A class for monads which can embed continuations.

Minimal complete definition

callCC

Methods

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

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) Source # 

Methods

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

MonadCont m => MonadCont (ExceptT e m) Source # 

Methods

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

MonadCont m => MonadCont (StateT s m) Source # 

Methods

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

MonadCont m => MonadCont (StateT s m) Source # 

Methods

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

MonadCont m => MonadCont (IdentityT * m) Source # 

Methods

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

MonadCont (ContT * r m) Source # 

Methods

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

MonadCont m => MonadCont (ReaderT * r m) Source # 

Methods

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

newtype ContT k r m 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) Source # 

Associated Types

type ReaderSuitable (ContT * r m :: * -> *) a :: Constraint Source #

Methods

ask :: ContT * r m r' Source #

local :: (ReaderSuitable (ContT * r m) a, ReaderSuitable (ContT * r m) r') => (r' -> r') -> ContT * r m a -> ContT * r m a Source #

reader :: (ReaderSuitable (ContT * r m) r', ReaderSuitable (ContT * r m) a) => (r' -> a) -> ContT * r m a Source #

(MonadState s m, Suitable m r) => MonadState s (ContT * r m) Source # 

Associated Types

type StateSuitable (ContT * r m :: * -> *) a :: Constraint Source #

Methods

get :: ContT * r m s Source #

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

state :: (StateSuitable (ContT * r m) a, StateSuitable (ContT * r m) s) => (s -> (a, s)) -> ContT * r m a Source #

MonadTrans (ContT * r) 

Methods

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

MonadTrans (ContT * r) Source # 

Associated Types

type SuitableLift (ContT * r :: (* -> *) -> * -> *) (m :: * -> *) a :: Constraint Source #

Methods

lift :: (Monad m, SuitableLift (ContT * r) m a) => m a -> ContT * r m a Source #

Monad (ContT k r m) 

Methods

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

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

return :: a -> ContT k r m a #

fail :: String -> ContT k r m a #

Functor (ContT k r m) 

Methods

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

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

MonadFail m => MonadFail (ContT * r m) 

Methods

fail :: String -> ContT * r m a #

Applicative (ContT k r m) 

Methods

pure :: a -> ContT k r m a #

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

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

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

MonadIO m => MonadIO (ContT * r m) 

Methods

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

Monad (ContT * r m) Source # 

Methods

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

Applicative (ContT * r m) Source # 

Methods

pure :: Suitable (ContT * r m) a => a -> ContT * r m a Source #

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

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

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

liftA :: Suitable (ContT * r m) a => FunType xs a -> AppVect (ContT * r m) xs -> ContT * r m a Source #

liftA2 :: Suitable (ContT * r m) c => (a -> b -> c) -> ContT * r m a -> ContT * r m b -> ContT * r m c Source #

liftA3 :: Suitable (ContT * r m) d => (a -> b -> c -> d) -> ContT * r m a -> ContT * r m b -> ContT * r m c -> ContT * r m d Source #

Functor (ContT * r m) Source # 

Associated Types

type Suitable (ContT * r m :: * -> *) a :: Constraint Source #

Methods

fmap :: Suitable (ContT * r m) b => (a -> b) -> ContT * r m a -> ContT * r m b Source #

(<$) :: Suitable (ContT * r m) a => a -> ContT * r m b -> ContT * r m a Source #

MonadCont (ContT * r m) Source # 

Methods

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

MonadIO m => MonadIO (ContT * r m) Source # 

Associated Types

type SuitableIO (ContT * r m :: * -> *) a :: Constraint Source #

Methods

liftIO :: SuitableIO (ContT * r m) a => IO a -> ContT * r m a Source #

type SuitableLift (ContT * r) m a Source # 
type SuitableLift (ContT * r) m a = Suitable m r
type Suitable (ContT * r m) a Source # 
type Suitable (ContT * r m) a = ()
type SuitableIO (ContT * r m) a Source # 
type SuitableIO (ContT * r m) a = (Suitable m r, SuitableIO m a)
type ReaderSuitable (ContT * r m) a Source # 
type StateSuitable (ContT * r m) a Source # 
type StateSuitable (ContT * r m) a = StateSuitable m a

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

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

mapContT :: (m r -> m r) -> ContT k r m a -> ContT k 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 k r m a -> ContT k r m b #

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

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.