-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Concrete 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. @package transformers @version 0.0.1.0 -- | The MonadTrans class. -- -- Inspired by the paper /Functional Programming with Overloading and -- Higher-Order Polymorphism/, Mark P Jones -- (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional -- Programming, 1995. module Control.Monad.Trans class MonadTrans t lift :: (MonadTrans t, Monad m) => m a -> t m a class (Monad m) => MonadIO m liftIO :: (MonadIO m) => IO a -> m a instance MonadIO IO -- |
-- -- 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 (Monad m) => Functor (ErrorT e m) instance (Error e) => MonadFix (Either e) instance (Error e) => MonadPlus (Either e) instance (Error e) => Monad (Either e) instance ErrorList Char instance Error IOException instance (ErrorList a) => Error [a] instance MonadPlus IO -- | 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 (Monad m) => Functor (ListT m) -- |
-- example :: Int -> Identity Int -- example x = return (x*x) ---- -- you can "run" it, using -- --
-- Main> runIdentity (example 42) -- 1764 :: Int ---- -- A typical use of the Identity monad is to derive a monad from a monad -- transformer. -- --
-- -- derive the Control.Monad.State.State monad using the Control.Monad.State.StateT monad transformer -- type Control.Monad.State.State s a = Control.Monad.State.StateT s Identity a ---- -- The runIdentity label is used in the type definition -- because it follows a style of monad definition that explicitly -- represents monad values as computations. In this style, a monadic -- computation is built up using the monadic operators and then the value -- of the computation is extracted using the run****** function. -- Because the Identity monad does not do any computation, its -- definition is trivial. For a better example of this style of monad, -- see the Control.Monad.State.State monad. newtype Identity a Identity :: a -> Identity a runIdentity :: Identity a -> a instance MonadFix Identity instance Monad Identity instance Functor Identity -- | Continuation monads. module Control.Monad.Trans.Cont -- | Continuation monad. Cont r a is a CPS 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. type Cont r = ContT r Identity cont :: ((a -> r) -> r) -> Cont r a -- | Runs a CPS computation, returns its result after applying the final -- continuation to it. runCont :: Cont r a -> (a -> r) -> r mapCont :: (r -> r) -> Cont r a -> Cont r a withCont :: ((b -> r) -> (a -> r)) -> Cont r a -> Cont r b -- | The continuation monad transformer. Can be used to add continuation -- handling to other monads. newtype ContT r m a ContT :: ((a -> m r) -> m r) -> ContT r m a runContT :: ContT r m a -> (a -> m r) -> m r mapContT :: (m r -> m r) -> ContT r m a -> ContT r m a withContT :: ((b -> m r) -> (a -> m r)) -> ContT r m a -> ContT r m b -- | callCC (call-with-current-continuation) calls its argument -- function, passing it the current continuation. It provides an escape -- continuation mechanism for use with continuation monads. Escape -- continuations one allow to abort the current computation and return a -- value immediately. They achieve a similar effect to -- Control.Monad.Trans.Error.throwError and -- Control.Monad.Trans.Error.catchError within an -- Control.Monad.Trans.Error.ErrorT monad. The advantage of this -- function over calling return is that it makes the continuation -- explicit, allowing more flexibility and better control. -- -- 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. callCC :: ((a -> ContT r m b) -> ContT r m a) -> ContT r m a -- | liftLocal ask local yields a local function -- for ContT r m. liftLocal :: (Monad m) => m r' -> ((r' -> r') -> m r -> m r) -> (r' -> r') -> ContT r m a -> ContT r m a instance (MonadIO m) => MonadIO (ContT r m) instance MonadTrans (ContT r) instance (Monad m) => Monad (ContT r m) instance Functor (ContT r m) -- | Declaration of the MonadReader class -- -- Inspired by the paper /Functional Programming with Overloading and -- Higher-Order Polymorphism/, Mark P Jones -- (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional -- Programming, 1995. module Control.Monad.Trans.Reader -- | The parameterizable reader monad. -- -- The return function creates a Reader that ignores the -- environment, and produces the given value. -- -- The binding operator >>= produces a Reader -- that uses the environment to extract the value its left-hand side, and -- then applies the bound function to that value in the same environment. type Reader r = ReaderT r Identity reader :: (r -> a) -> Reader r a -- | Runs Reader and extracts the final value from it. runReader :: Reader r a -> r -> a mapReader :: (a -> b) -> Reader r a -> Reader r b -- | A more general version of local. withReader :: (r' -> r) -> Reader r a -> Reader r' a -- | The reader monad transformer. Can be used to add environment reading -- functionality to other monads. newtype ReaderT r m a ReaderT :: (r -> m a) -> ReaderT r m a runReaderT :: ReaderT r m a -> r -> m a mapReaderT :: (m a -> n b) -> ReaderT w m a -> ReaderT w n b withReaderT :: (r' -> r) -> ReaderT r m a -> ReaderT r' m a ask :: (Monad m) => ReaderT r m r local :: (Monad m) => (r -> r) -> ReaderT r m a -> ReaderT r m a 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 (Monad m) => Functor (ReaderT r m) -- | Lazy RWS monad. -- -- Inspired by the paper /Functional Programming with Overloading and -- Higher-Order Polymorphism/, Mark P Jones -- (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional -- Programming, 1995. 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 -- | Lift a callCC operation to the new monad. 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 (Monad m) => Functor (RWST r w s m) -- | Combination Reader, Writer and State monad transformer. -- -- Inspired by the paper /Functional Programming with Overloading and -- Higher-Order Polymorphism/, Mark P Jones -- (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional -- Programming, 1995. module Control.Monad.Trans.RWS -- | Strict RWS monad. -- -- Inspired by the paper /Functional Programming with Overloading and -- Higher-Order Polymorphism/, Mark P Jones -- (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional -- Programming, 1995. 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 -- | Lift a callCC operation to the new monad. 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 (Monad m) => Functor (RWST r w s m) -- | Lazy state monads. -- -- This module is inspired by the paper /Functional Programming with -- Overloading and Higher-Order Polymorphism/, Mark P Jones -- (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional -- Programming, 1995. -- -- See below for examples. module Control.Monad.Trans.State.Lazy -- | 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 state :: (s -> (a, s)) -> State s a 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) -- | Similar to evalState evalStateT :: (Monad m) => StateT s m a -> s -> m a -- | Similar to execState execStateT :: (Monad m) => StateT s m a -> s -> m s -- | Similar to mapState mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b -- | Similar to withState 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 -- | Lift a callCC operation to the new monad. 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 (Monad m) => Functor (StateT s m) -- | State monads. -- -- This module is inspired by the paper /Functional Programming with -- Overloading and Higher-Order Polymorphism/, Mark P Jones -- (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional -- Programming, 1995. module Control.Monad.Trans.State -- | Strict state monads. -- -- This module is inspired by the paper /Functional Programming with -- Overloading and Higher-Order Polymorphism/, Mark P Jones -- (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional -- Programming, 1995. -- -- 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 state :: (s -> (a, s)) -> State s a 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) -- | Similar to evalState evalStateT :: (Monad m) => StateT s m a -> s -> m a -- | Similar to execState execStateT :: (Monad m) => StateT s m a -> s -> m s -- | Similar to mapState mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b -- | Similar to withState 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 -- | Lift a callCC operation to the new monad. 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 (Monad m) => Functor (StateT s m) -- | Lazy writer monads. -- -- Inspired by the paper /Functional Programming with Overloading and -- Higher-Order Polymorphism/, Mark P Jones -- (http://web.cecs.pdx.edu/~mpj/pubs/springschool.html) Advanced -- School of Functional Programming, 1995. 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 (Monad m) => Functor (WriterT w m) -- | The WriterT monad transformer. -- -- Inspired by the paper /Functional Programming with Overloading and -- Higher-Order Polymorphism/, Mark P Jones -- (http://web.cecs.pdx.edu/~mpj/pubs/springschool.html) Advanced -- School of Functional Programming, 1995. module Control.Monad.Trans.Writer -- | Strict writer monads. -- -- Inspired by the paper /Functional Programming with Overloading and -- Higher-Order Polymorphism/, Mark P Jones -- (http://web.cecs.pdx.edu/~mpj/pubs/springschool.html) Advanced -- School of Functional Programming, 1995. 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 (Monad m) => Functor (WriterT w m)