-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Concrete functor and monad transformers -- -- Haskell 98 part of a monad transformer library, inspired by the paper -- "Functional Programming with Overloading and Higher-Order -- Polymorphism", by Mark P Jones, in Advanced School of Functional -- Programming, 1995 -- (http://web.cecs.pdx.edu/~mpj/pubs/springschool.html). -- -- This part contains the monad transformer class, the concrete monad -- transformers, operations and liftings. It can be used on its own in -- Haskell 98 code, or with the monad classes in the monads-fd -- or monads-tf packages, which automatically lift operations -- introduced by monad transformers through other transformers. @package transformers @version 0.2.0.0 -- | The constant functor. module Data.Functor.Constant -- | Constant functor. newtype Constant a b Constant :: a -> Constant a b getConstant :: Constant a b -> a instance (Monoid a) => Applicative (Constant a) instance Traversable (Constant a) instance Foldable (Constant a) instance Functor (Constant a) -- | Composition of functors. module Data.Functor.Compose -- | Right-to-left composition of functors. newtype Compose f g a Compose :: f (g a) -> Compose f g a getCompose :: Compose f g a -> f (g a) instance (Applicative f, Applicative g) => Applicative (Compose f g) instance (Traversable f, Traversable g) => Traversable (Compose f g) instance (Foldable f, Foldable g) => Foldable (Compose f g) instance (Functor f, Functor g) => Functor (Compose f g) -- | The identity functor and monad. -- -- This trivial type constructor serves two purposes: -- --
-- -- wraps IO action that can throw an error e -- type ErrorWithIO e a = ErrorT e IO a -- ==> ErrorT (IO (Either e a)) -- -- -- IO monad wrapped in StateT inside of ErrorT -- type ErrorAndStateWithIO e s a = ErrorT e (StateT s IO) a -- ==> ErrorT (StateT s IO (Either e a)) -- ==> ErrorT (StateT (s -> IO (Either e a,s))) --newtype ErrorT e m a ErrorT :: m (Either e a) -> ErrorT e m a runErrorT :: ErrorT e m a -> m (Either e a) mapErrorT :: (m (Either e a) -> n (Either e' b)) -> ErrorT e m a -> ErrorT e' n b -- | Signal an error throwError :: (Monad m, Error e) => e -> ErrorT e m a -- | Handle an error catchError :: (Monad m, Error e) => ErrorT e m a -> (e -> ErrorT e m a) -> ErrorT e m a -- | Lift a callCC operation to the new monad. liftCallCC :: (((Either e a -> m (Either e b)) -> m (Either e a)) -> m (Either e a)) -> ((a -> ErrorT e m b) -> ErrorT e m a) -> ErrorT e m a -- | Lift a listen operation to the new monad. liftListen :: (Monad m) => (m (Either e a) -> m (Either e a, w)) -> ErrorT e m a -> ErrorT e m (a, w) -- | Lift a pass operation to the new monad. liftPass :: (Monad m) => (m (Either e a, w -> w) -> m (Either e a)) -> ErrorT e m (a, w -> w) -> ErrorT e m a instance (Error e, MonadIO m) => MonadIO (ErrorT e m) instance (Error e) => MonadTrans (ErrorT e) instance (MonadFix m, Error e) => MonadFix (ErrorT e m) instance (Monad m, Error e) => MonadPlus (ErrorT e m) instance (Monad m, Error e) => Monad (ErrorT e m) instance (Functor m, Monad m, Error e) => Alternative (ErrorT e m) instance (Functor m, Monad m) => Applicative (ErrorT e m) instance (Functor m) => Functor (ErrorT e m) instance (Error e) => MonadFix (Either e) instance (Error e) => MonadPlus (Either e) instance (Error e) => Monad (Either e) instance (Error e) => Alternative (Either e) instance Applicative (Either e) instance ErrorList Char instance (ErrorList a) => Error [a] instance Error IOException instance MonadPlus IO -- | The identity monad transformer. -- -- This is useful for functions parameterized by a monad transformer. module Control.Monad.Trans.Identity -- | The trivial monad transformer, which maps a monad to an equivalent -- monad. newtype IdentityT m a IdentityT :: m a -> IdentityT m a runIdentityT :: IdentityT m a -> m a -- | Lift a unary operation to the new monad. mapIdentityT :: (m a -> n b) -> IdentityT m a -> IdentityT n b -- | Lift a catchError operation to the new monad. liftCatch :: (m a -> (e -> m a) -> m a) -> IdentityT m a -> (e -> IdentityT m a) -> IdentityT m a -- | Lift a callCC operation to the new monad. liftCallCC :: (((a -> m b) -> m a) -> m a) -> ((a -> IdentityT m b) -> IdentityT m a) -> IdentityT m a instance MonadTrans IdentityT instance (MonadIO m) => MonadIO (IdentityT m) instance (MonadPlus m) => MonadPlus (IdentityT m) instance (Monad m) => Monad (IdentityT m) instance (Alternative m) => Alternative (IdentityT m) instance (Applicative m) => Applicative (IdentityT m) instance (Functor m) => Functor (IdentityT m) -- | The List monad. module Control.Monad.Trans.List -- | Parameterizable list monad, with an inner monad. -- -- Note: this does not yield a monad unless the argument monad is -- commutative. newtype ListT m a ListT :: m [a] -> ListT m a runListT :: ListT m a -> m [a] mapListT :: (m [a] -> n [b]) -> ListT m a -> ListT n b -- | Lift a callCC operation to the new monad. liftCallCC :: ((([a] -> m [b]) -> m [a]) -> m [a]) -> ((a -> ListT m b) -> ListT m a) -> ListT m a -- | Lift a catchError operation to the new monad. liftCatch :: (m [a] -> (e -> m [a]) -> m [a]) -> ListT m a -> (e -> ListT m a) -> ListT m a instance (MonadIO m) => MonadIO (ListT m) instance MonadTrans ListT instance (Monad m) => MonadPlus (ListT m) instance (Monad m) => Monad (ListT m) instance (Applicative m) => Alternative (ListT m) instance (Applicative m) => Applicative (ListT m) instance (Functor m) => Functor (ListT m) -- | Declaration of the MaybeT monad transformer. module Control.Monad.Trans.Maybe newtype MaybeT m a MaybeT :: m (Maybe a) -> MaybeT m a runMaybeT :: MaybeT m a -> m (Maybe a) mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b -- | Lift a callCC operation to the new monad. liftCallCC :: (((Maybe a -> m (Maybe b)) -> m (Maybe a)) -> m (Maybe a)) -> ((a -> MaybeT m b) -> MaybeT m a) -> MaybeT m a -- | Lift a catchError operation to the new monad. liftCatch :: (m (Maybe a) -> (e -> m (Maybe a)) -> m (Maybe a)) -> MaybeT m a -> (e -> MaybeT m a) -> MaybeT m a -- | Lift a listen operation to the new monad. liftListen :: (Monad m) => (m (Maybe a) -> m (Maybe a, w)) -> MaybeT m a -> MaybeT m (a, w) -- | Lift a pass operation to the new monad. liftPass :: (Monad m) => (m (Maybe a, w -> w) -> m (Maybe a)) -> MaybeT m (a, w -> w) -> MaybeT m a instance (MonadIO m) => MonadIO (MaybeT m) instance MonadTrans MaybeT instance (Monad m) => MonadPlus (MaybeT m) instance (Monad m) => Monad (MaybeT m) instance (Functor m, Monad m) => Alternative (MaybeT m) instance (Functor m, Monad m) => Applicative (MaybeT m) instance (Functor m) => Functor (MaybeT m) -- | Declaration of the ReaderT monad transformer, which adds a -- static environment to a given monad. -- -- If the computation is to modify the stored information, use -- Control.Monad.Trans.State instead. module Control.Monad.Trans.Reader -- | The parameterizable reader monad. -- -- Computations are functions of a shared environment. -- -- The return function ignores the environment, while -- >>= passes the inherited environment to both -- subcomputations. type Reader r = ReaderT r Identity -- | Constructor for computations in the reader monad. reader :: (r -> a) -> Reader r a -- | Runs a Reader and extracts the final value from it. runReader :: Reader r a -> r -> a -- | Transform the value returned by a Reader. mapReader :: (a -> b) -> Reader r a -> Reader r b -- | Execute a computation in a modified environment (a specialization of -- withReaderT). withReader :: (r' -> r) -> Reader r a -> Reader r' a -- | The reader monad transformer, which adds a read-only environment to -- the given monad. -- -- The return function ignores the environment, while -- >>= passes the inherited environment to both -- subcomputations. newtype ReaderT r m a ReaderT :: (r -> m a) -> ReaderT r m a -- | The underlying computation, as a function of the environment. runReaderT :: ReaderT r m a -> r -> m a -- | Transform the computation inside a ReaderT. mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b -- | Execute a computation in a modified environment (a more general -- version of local). withReaderT :: (r' -> r) -> ReaderT r m a -> ReaderT r' m a -- | Fetch the value of the environment. ask :: (Monad m) => ReaderT r m r -- | Execute a computation in a modified environment (a specialization of -- withReaderT). local :: (Monad m) => (r -> r) -> ReaderT r m a -> ReaderT r m a -- | Retrieve a function of the current environment. asks :: (Monad m) => (r -> a) -> ReaderT r m a -- | Lift a callCC operation to the new monad. liftCallCC :: (((a -> m b) -> m a) -> m a) -> ((a -> ReaderT r m b) -> ReaderT r m a) -> ReaderT r m a -- | Lift a catchError operation to the new monad. liftCatch :: (m a -> (e -> m a) -> m a) -> ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a instance (MonadIO m) => MonadIO (ReaderT r m) instance MonadTrans (ReaderT r) instance (MonadFix m) => MonadFix (ReaderT r m) instance (MonadPlus m) => MonadPlus (ReaderT r m) instance (Monad m) => Monad (ReaderT r m) instance (Alternative m) => Alternative (ReaderT r m) instance (Applicative m) => Applicative (ReaderT r m) instance (Functor m) => Functor (ReaderT r m) -- | Lazy RWS monad. module Control.Monad.Trans.RWS.Lazy type RWS r w s = RWST r w s Identity rws :: (r -> s -> (a, s, w)) -> RWS r w s a runRWS :: RWS r w s a -> r -> s -> (a, s, w) evalRWS :: RWS r w s a -> r -> s -> (a, w) execRWS :: RWS r w s a -> r -> s -> (s, w) mapRWS :: ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b withRWS :: (r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a newtype RWST r w s m a RWST :: (r -> s -> m (a, s, w)) -> RWST r w s m a runRWST :: RWST r w s m a -> r -> s -> m (a, s, w) evalRWST :: (Monad m) => RWST r w s m a -> r -> s -> m (a, w) execRWST :: (Monad m) => RWST r w s m a -> r -> s -> m (s, w) mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b withRWST :: (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a ask :: (Monoid w, Monad m) => RWST r w s m r local :: (Monoid w, Monad m) => (r -> r) -> RWST r w s m a -> RWST r w s m a asks :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a tell :: (Monoid w, Monad m) => w -> RWST r w s m () listen :: (Monoid w, Monad m) => RWST r w s m a -> RWST r w s m (a, w) pass :: (Monoid w, Monad m) => RWST r w s m (a, w -> w) -> RWST r w s m a listens :: (Monoid w, Monad m) => (w -> b) -> RWST r w s m a -> RWST r w s m (a, b) censor :: (Monoid w, Monad m) => (w -> w) -> RWST r w s m a -> RWST r w s m a get :: (Monoid w, Monad m) => RWST r w s m s put :: (Monoid w, Monad m) => s -> RWST r w s m () -- | Monadic state transformer. -- -- Maps an old state to a new state inside a state monad. The old state -- is thrown away. modify :: (Monoid w, Monad m) => (s -> s) -> RWST r w s m () -- | Gets specific component of the state, using a projection function -- supplied. gets :: (Monoid w, Monad m) => (s -> a) -> RWST r w s m a -- | Uniform lifting of a callCC operation to the new monad. This -- version rolls back to the original state on entering the continuation. liftCallCC :: (Monoid w) => ((((a, s, w) -> m (b, s, w)) -> m (a, s, w)) -> m (a, s, w)) -> ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a -- | In-situ lifting of a callCC operation to the new monad. This -- version uses the current state on entering the continuation. liftCallCC' :: (Monoid w) => ((((a, s, w) -> m (b, s, w)) -> m (a, s, w)) -> m (a, s, w)) -> ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a -- | Lift a catchError operation to the new monad. liftCatch :: (m (a, s, w) -> (e -> m (a, s, w)) -> m (a, s, w)) -> RWST l w s m a -> (e -> RWST l w s m a) -> RWST l w s m a instance (Monoid w, MonadIO m) => MonadIO (RWST r w s m) instance (Monoid w) => MonadTrans (RWST r w s) instance (Monoid w, MonadFix m) => MonadFix (RWST r w s m) instance (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) instance (Monoid w, Monad m) => Monad (RWST r w s m) instance (Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) instance (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) instance (Functor m) => Functor (RWST r w s m) -- | A monad transformer that combines ReaderT, WriterT -- and StateT. This version is lazy; for a strict version, see -- Control.Monad.Trans.RWS.Strict, which has the same interface. module Control.Monad.Trans.RWS -- | Strict RWS monad. module Control.Monad.Trans.RWS.Strict type RWS r w s = RWST r w s Identity rws :: (r -> s -> (a, s, w)) -> RWS r w s a runRWS :: RWS r w s a -> r -> s -> (a, s, w) evalRWS :: RWS r w s a -> r -> s -> (a, w) execRWS :: RWS r w s a -> r -> s -> (s, w) mapRWS :: ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b withRWS :: (r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a newtype RWST r w s m a RWST :: (r -> s -> m (a, s, w)) -> RWST r w s m a runRWST :: RWST r w s m a -> r -> s -> m (a, s, w) evalRWST :: (Monad m) => RWST r w s m a -> r -> s -> m (a, w) execRWST :: (Monad m) => RWST r w s m a -> r -> s -> m (s, w) mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b withRWST :: (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a ask :: (Monoid w, Monad m) => RWST r w s m r local :: (Monoid w, Monad m) => (r -> r) -> RWST r w s m a -> RWST r w s m a asks :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a tell :: (Monoid w, Monad m) => w -> RWST r w s m () listen :: (Monoid w, Monad m) => RWST r w s m a -> RWST r w s m (a, w) pass :: (Monoid w, Monad m) => RWST r w s m (a, w -> w) -> RWST r w s m a listens :: (Monoid w, Monad m) => (w -> b) -> RWST r w s m a -> RWST r w s m (a, b) censor :: (Monoid w, Monad m) => (w -> w) -> RWST r w s m a -> RWST r w s m a get :: (Monoid w, Monad m) => RWST r w s m s put :: (Monoid w, Monad m) => s -> RWST r w s m () -- | Monadic state transformer. -- -- Maps an old state to a new state inside a state monad. The old state -- is thrown away. modify :: (Monoid w, Monad m) => (s -> s) -> RWST r w s m () -- | Gets specific component of the state, using a projection function -- supplied. gets :: (Monoid w, Monad m) => (s -> a) -> RWST r w s m a -- | Uniform lifting of a callCC operation to the new monad. This -- version rolls back to the original state on entering the continuation. liftCallCC :: (Monoid w) => ((((a, s, w) -> m (b, s, w)) -> m (a, s, w)) -> m (a, s, w)) -> ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a -- | In-situ lifting of a callCC operation to the new monad. This -- version uses the current state on entering the continuation. liftCallCC' :: (Monoid w) => ((((a, s, w) -> m (b, s, w)) -> m (a, s, w)) -> m (a, s, w)) -> ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a -- | Lift a catchError operation to the new monad. liftCatch :: (m (a, s, w) -> (e -> m (a, s, w)) -> m (a, s, w)) -> RWST l w s m a -> (e -> RWST l w s m a) -> RWST l w s m a instance (Monoid w, MonadIO m) => MonadIO (RWST r w s m) instance (Monoid w) => MonadTrans (RWST r w s) instance (Monoid w, MonadFix m) => MonadFix (RWST r w s m) instance (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) instance (Monoid w, Monad m) => Monad (RWST r w s m) instance (Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) instance (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) instance (Functor m) => Functor (RWST r w s m) -- | Lazy state monads, passing an updateable state through a computation. -- -- Some computations may not require the full power if state -- transformers: -- --
-- evalState m s = fst (runState m s) --evalState :: State s a -> s -> a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- --
-- execState m s = snd (runState m s) --execState :: State s a -> s -> s -- | Map a stateful computation from one (return value, state) pair to -- another. For instance, to convert numberTree from a function that -- returns a tree to a function that returns the sum of the numbered tree -- (see the Examples section for numberTree and sumTree) you may write: -- --
-- sumNumberedTree :: (Eq a) => Tree a -> State (Table a) Int -- sumNumberedTree = mapState (\ (t, tab) -> (sumTree t, tab)) . numberTree --mapState :: ((a, s) -> (b, s)) -> State s a -> State s b -- | Apply this function to this state and return the resulting state. withState :: (s -> s) -> State s a -> State s a -- | A parameterizable state monad for encapsulating an inner monad. -- -- The StateT Monad structure is parameterized over two things: -- --
-- type Parser a = StateT String [] a -- ==> StateT (String -> [(a,String)]) ---- -- For example, item can be written as: -- --
-- item = do (x:xs) <- get -- put xs -- return x -- -- type BoringState s a = StateT s Identity a -- ==> StateT (s -> Identity (a,s)) -- -- type StateWithIO s a = StateT s IO a -- ==> StateT (s -> IO (a,s)) -- -- type StateWithErr s a = StateT s Maybe a -- ==> StateT (s -> Maybe (a,s)) --newtype StateT s m a StateT :: (s -> m (a, s)) -> StateT s m a runStateT :: StateT s m a -> s -> m (a, s) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- --
-- evalStateT m s = liftM fst (runStateT m s) --evalStateT :: (Monad m) => StateT s m a -> s -> m a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- --
-- execStateT m s = liftM snd (runStateT m s) --execStateT :: (Monad m) => StateT s m a -> s -> m s -- | Map a stateful computation from one (return value, state) pair to -- another. For instance, to convert numberTree from a function that -- returns a tree to a function that returns the sum of the numbered tree -- (see the Examples section for numberTree and sumTree) you may write: -- --
-- sumNumberedTree :: (Eq a) => Tree a -> State (Table a) Int -- sumNumberedTree = mapState (\ (t, tab) -> (sumTree t, tab)) . numberTree --mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b -- | Apply this function to this state and return the resulting state. withStateT :: (s -> s) -> StateT s m a -> StateT s m a -- | Fetch the current value of the state within the monad. get :: (Monad m) => StateT s m s -- | put s sets the state within the monad to s. put :: (Monad m) => s -> StateT s m () -- | Monadic state transformer. -- -- Maps an old state to a new state inside a state monad. The old state -- is thrown away. modify :: (Monad m) => (s -> s) -> StateT s m () -- | Get a specific component of the state, using a projection function -- supplied. gets :: (Monad m) => (s -> a) -> StateT s m a -- | Uniform lifting of a callCC operation to the new monad. This -- version rolls back to the original state on entering the continuation. liftCallCC :: ((((a, s) -> m (b, s)) -> m (a, s)) -> m (a, s)) -> ((a -> StateT s m b) -> StateT s m a) -> StateT s m a -- | In-situ lifting of a callCC operation to the new monad. This -- version uses the current state on entering the continuation. It does -- not satisfy the laws of a monad transformer. liftCallCC' :: ((((a, s) -> m (b, s)) -> m (a, s)) -> m (a, s)) -> ((a -> StateT s m b) -> StateT s m a) -> StateT s m a -- | Lift a catchError operation to the new monad. liftCatch :: (m (a, s) -> (e -> m (a, s)) -> m (a, s)) -> StateT s m a -> (e -> StateT s m a) -> StateT s m a -- | Lift a listen operation to the new monad. liftListen :: (Monad m) => (m (a, s) -> m ((a, s), w)) -> StateT s m a -> StateT s m (a, w) -- | Lift a pass operation to the new monad. liftPass :: (Monad m) => (m ((a, s), b) -> m (a, s)) -> StateT s m (a, b) -> StateT s m a instance (MonadIO m) => MonadIO (StateT s m) instance MonadTrans (StateT s) instance (MonadFix m) => MonadFix (StateT s m) instance (MonadPlus m) => MonadPlus (StateT s m) instance (Monad m) => Monad (StateT s m) instance (Functor m, MonadPlus m) => Alternative (StateT s m) instance (Functor m, Monad m) => Applicative (StateT s m) instance (Functor m) => Functor (StateT s m) -- | State monads. This version is lazy; for a strict version, see -- Control.Monad.Trans.State.Strict, which has the same interface. module Control.Monad.Trans.State -- | Strict state monads. -- -- See below for examples. module Control.Monad.Trans.State.Strict -- | A parameterizable state monad where s is the type of the state -- to carry and a is the type of the return value. type State s = StateT s Identity -- | Construct a state monad computation from a function. (The inverse of -- runState.) state :: (s -> (a, s)) -> State s a -- | Unwrap a state monad computation as a function. (The inverse of -- state.) runState :: State s a -> s -> (a, s) -- | Evaluate this state monad with the given initial state,throwing away -- the final state. Very much like fst composed with -- runstate. evalState :: State s a -> s -> a -- | Execute this state and return the new state, throwing away the return -- value. Very much like snd composed with runstate. execState :: State s a -> s -> s -- | Map a stateful computation from one (return value, state) pair to -- another. For instance, to convert numberTree from a function that -- returns a tree to a function that returns the sum of the numbered tree -- (see the Examples section for numberTree and sumTree) you may write: -- --
-- sumNumberedTree :: (Eq a) => Tree a -> State (Table a) Int -- sumNumberedTree = mapState (\ (t, tab) -> (sumTree t, tab)) . numberTree --mapState :: ((a, s) -> (b, s)) -> State s a -> State s b -- | Apply this function to this state and return the resulting state. withState :: (s -> s) -> State s a -> State s a -- | A parameterizable state monad for encapsulating an inner monad. -- -- The StateT Monad structure is parameterized over two things: -- --
-- type Parser a = StateT String [] a -- ==> StateT (String -> [(a,String)]) ---- -- For example, item can be written as: -- --
-- item = do (x:xs) <- get -- put xs -- return x -- -- type BoringState s a = StateT s Identity a -- ==> StateT (s -> Identity (a,s)) -- -- type StateWithIO s a = StateT s IO a -- ==> StateT (s -> IO (a,s)) -- -- type StateWithErr s a = StateT s Maybe a -- ==> StateT (s -> Maybe (a,s)) --newtype StateT s m a StateT :: (s -> m (a, s)) -> StateT s m a runStateT :: StateT s m a -> s -> m (a, s) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- --
-- evalStateT m s = liftM fst (runStateT m s) --evalStateT :: (Monad m) => StateT s m a -> s -> m a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- --
-- execStateT m s = liftM snd (runStateT m s) --execStateT :: (Monad m) => StateT s m a -> s -> m s -- | Map a stateful computation from one (return value, state) pair to -- another. For instance, to convert numberTree from a function that -- returns a tree to a function that returns the sum of the numbered tree -- (see the Examples section for numberTree and sumTree) you may write: -- --
-- sumNumberedTree :: (Eq a) => Tree a -> State (Table a) Int -- sumNumberedTree = mapState (\ (t, tab) -> (sumTree t, tab)) . numberTree --mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b -- | Apply this function to this state and return the resulting state. withStateT :: (s -> s) -> StateT s m a -> StateT s m a get :: (Monad m) => StateT s m s put :: (Monad m) => s -> StateT s m () -- | Monadic state transformer. -- -- Maps an old state to a new state inside a state monad. The old state -- is thrown away. modify :: (Monad m) => (s -> s) -> StateT s m () -- | Gets specific component of the state, using a projection function -- supplied. gets :: (Monad m) => (s -> a) -> StateT s m a -- | Uniform lifting of a callCC operation to the new monad. This -- version rolls back to the original state on entering the continuation. liftCallCC :: ((((a, s) -> m (b, s)) -> m (a, s)) -> m (a, s)) -> ((a -> StateT s m b) -> StateT s m a) -> StateT s m a -- | In-situ lifting of a callCC operation to the new monad. This -- version uses the current state on entering the continuation. It does -- not satisfy the laws of a monad transformer. liftCallCC' :: ((((a, s) -> m (b, s)) -> m (a, s)) -> m (a, s)) -> ((a -> StateT s m b) -> StateT s m a) -> StateT s m a -- | Lift a catchError operation to the new monad. liftCatch :: (m (a, s) -> (e -> m (a, s)) -> m (a, s)) -> StateT s m a -> (e -> StateT s m a) -> StateT s m a -- | Lift a listen operation to the new monad. liftListen :: (Monad m) => (m (a, s) -> m ((a, s), w)) -> StateT s m a -> StateT s m (a, w) -- | Lift a pass operation to the new monad. liftPass :: (Monad m) => (m ((a, s), b) -> m (a, s)) -> StateT s m (a, b) -> StateT s m a instance (MonadIO m) => MonadIO (StateT s m) instance MonadTrans (StateT s) instance (MonadFix m) => MonadFix (StateT s m) instance (MonadPlus m) => MonadPlus (StateT s m) instance (Monad m) => Monad (StateT s m) instance (Functor m, MonadPlus m) => Alternative (StateT s m) instance (Functor m, Monad m) => Applicative (StateT s m) instance (Functor m) => Functor (StateT s m) -- | Lazy writer monads. module Control.Monad.Trans.Writer.Lazy type Writer w = WriterT w Identity writer :: (a, w) -> Writer w a runWriter :: Writer w a -> (a, w) execWriter :: Writer w a -> w mapWriter :: ((a, w) -> (b, w')) -> Writer w a -> Writer w' b newtype WriterT w m a WriterT :: m (a, w) -> WriterT w m a runWriterT :: WriterT w m a -> m (a, w) execWriterT :: (Monad m) => WriterT w m a -> m w mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b tell :: (Monoid w, Monad m) => w -> WriterT w m () listen :: (Monoid w, Monad m) => WriterT w m a -> WriterT w m (a, w) pass :: (Monoid w, Monad m) => WriterT w m (a, w -> w) -> WriterT w m a listens :: (Monoid w, Monad m) => (w -> b) -> WriterT w m a -> WriterT w m (a, b) censor :: (Monoid w, Monad m) => (w -> w) -> WriterT w m a -> WriterT w m a -- | Lift a callCC operation to the new monad. liftCallCC :: (Monoid w) => ((((a, w) -> m (b, w)) -> m (a, w)) -> m (a, w)) -> ((a -> WriterT w m b) -> WriterT w m a) -> WriterT w m a -- | Lift a catchError operation to the new monad. liftCatch :: (m (a, w) -> (e -> m (a, w)) -> m (a, w)) -> WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a instance (Monoid w, MonadIO m) => MonadIO (WriterT w m) instance (Monoid w) => MonadTrans (WriterT w) instance (Monoid w, MonadFix m) => MonadFix (WriterT w m) instance (Monoid w, MonadPlus m) => MonadPlus (WriterT w m) instance (Monoid w, Monad m) => Monad (WriterT w m) instance (Monoid w, Alternative m) => Alternative (WriterT w m) instance (Monoid w, Applicative m) => Applicative (WriterT w m) instance (Functor m) => Functor (WriterT w m) -- | The WriterT monad transformer. This version is lazy; for a strict -- version, see Control.Monad.Trans.Writer.Strict, which has the -- same interface. module Control.Monad.Trans.Writer -- | Strict writer monads. module Control.Monad.Trans.Writer.Strict type Writer w = WriterT w Identity writer :: (a, w) -> Writer w a runWriter :: Writer w a -> (a, w) execWriter :: Writer w a -> w mapWriter :: ((a, w) -> (b, w')) -> Writer w a -> Writer w' b newtype WriterT w m a WriterT :: m (a, w) -> WriterT w m a runWriterT :: WriterT w m a -> m (a, w) execWriterT :: (Monad m) => WriterT w m a -> m w mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b tell :: (Monoid w, Monad m) => w -> WriterT w m () listen :: (Monoid w, Monad m) => WriterT w m a -> WriterT w m (a, w) pass :: (Monoid w, Monad m) => WriterT w m (a, w -> w) -> WriterT w m a listens :: (Monoid w, Monad m) => (w -> b) -> WriterT w m a -> WriterT w m (a, b) censor :: (Monoid w, Monad m) => (w -> w) -> WriterT w m a -> WriterT w m a -- | Lift a callCC operation to the new monad. liftCallCC :: (Monoid w) => ((((a, w) -> m (b, w)) -> m (a, w)) -> m (a, w)) -> ((a -> WriterT w m b) -> WriterT w m a) -> WriterT w m a -- | Lift a catchError operation to the new monad. liftCatch :: (m (a, w) -> (e -> m (a, w)) -> m (a, w)) -> WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a instance (Monoid w, MonadIO m) => MonadIO (WriterT w m) instance (Monoid w) => MonadTrans (WriterT w) instance (Monoid w, MonadFix m) => MonadFix (WriterT w m) instance (Monoid w, MonadPlus m) => MonadPlus (WriterT w m) instance (Monoid w, Monad m) => Monad (WriterT w m) instance (Monoid w, Alternative m) => Alternative (WriterT w m) instance (Monoid w, Applicative m) => Applicative (WriterT w m) instance (Functor m) => Functor (WriterT w m)