-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Monad transformers and classes -- @package ether @version 0.2.1.0 -- | Template Haskell utilities. module Control.Ether.TH -- | Creates a tag and a value-level proxy for it. -- -- ethereal "Foo" "foo" generates the following code: -- --
--   data Foo
--   foo :: Proxy Foo
--   foo = Proxy
--   
ethereal :: String -> String -> DecsQ -- | Type-level machinery for tag manipulation. module Control.Ether.Tagged -- | The Taggable class defines the type families to manage tags in -- monad transformer stacks. Its kind is restricted to * -> * -- to prevent incorrect instances. class Taggable (m :: * -> *) where type family Tag m :: Maybe * type family Inner m :: Maybe (* -> *) type instance Tag m = Nothing type instance Inner m = Nothing -- | The Tagged type class establishes a relationship between a -- tagged monad transformer and its untagged counterpart. class (Taggable m, Tag m ~ Just tag) => Tagged m tag | m -> tag where type family Untagged m :: * -> * tagged _ = pack untagged _ = unpack tagged :: Tagged m tag => proxy tag -> Untagged m a -> m a untagged :: Tagged m tag => proxy tag -> m a -> Untagged m a -- | The Tags type function returns a type-level list of all tags in -- a monad transformer stack. Requires Taggable instances. type Tags (m :: * -> *) = MaybeToList (Tag m) ++ ListMapTag (Inners m) -- | The Inners type function recursively applies Inner and -- returns the results in a type-level list. type Inners m = Inners' (Inner m) -- | The main purpose of the UniqueTag class is to provide clear -- error messages when the tag uniqueness property is violated. You -- should never write instances for it unless you know what you're doing. class UniqueTag a -- | The UniqueTags constraint placed on a type variable -- representing a monad transformer stack ensures that every tag in the -- stack appears only once. -- | Type-restricted version of id that adds a UniqueTags -- constraint to the provided monadic value. ensureUniqueTags :: UniqueTags m => m a -> m a instance Taggable (WriterT w m) instance Taggable (WriterT w m) instance Taggable (StateT s m) instance Taggable (StateT s m) instance Taggable (ReaderT r m) instance Taggable (MaybeT m) instance Taggable (ListT m) instance Taggable (IdentityT m) instance Taggable (ExceptT e m) instance Taggable (ContT r m) instance Taggable (ST s) instance Taggable (ST s) instance Taggable Proxy instance Taggable (Either e) instance Taggable STM instance Taggable ((->) r) instance Taggable First instance Taggable Last instance Taggable Maybe instance Taggable Identity instance Taggable IO -- | See Control.Monad.Trans.Reader. module Control.Monad.Trans.Ether.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 tag r = ReaderT tag r Identity -- | Constructor for computations in the reader monad (the inverse of -- runReader). reader :: Monad m => proxy tag -> (r -> a) -> ReaderT tag r m a -- | Runs a ReaderT with the given environment and returns the vinal -- value. runReader :: proxy tag -> Reader tag r a -> 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. data ReaderT tag r m a -- | Constructor for computations in the reader monad transformer. readerT :: proxy tag -> (r -> m a) -> ReaderT tag r m a -- | Runs a ReaderT with the given environment and returns the vinal -- value. runReaderT :: proxy tag -> ReaderT tag r m a -> r -> m a -- | Transform the computation inside a ReaderT. -- -- mapReaderT :: proxy tag -> (m a -> n b) -> ReaderT tag r m a -> ReaderT tag r n b -- | Execute a computation in a modified environment (a more general -- version of local). -- -- withReaderT :: proxy tag -> (r' -> r) -> ReaderT tag r m a -> ReaderT tag r' m a -- | Fetch the value of the environment. ask :: Monad m => proxy tag -> ReaderT tag r m r -- | Execute a computation in a modified environment (a specialization of -- withReaderT). -- -- local :: proxy tag -> (r -> r) -> ReaderT tag r m a -> ReaderT tag r m a -- | Lift a catchE operation to the new monad. liftCatch :: proxy tag -> Catch e m a -> Catch e (ReaderT tag r m) a -- | Lift a callCC operation to the new monad. liftCallCC :: proxy tag -> CallCC m a b -> CallCC (ReaderT tag r m) a b instance Generic (ReaderT tag r m a) instance Functor m => Functor (ReaderT tag r m) instance Applicative m => Applicative (ReaderT tag r m) instance Alternative m => Alternative (ReaderT tag r m) instance Monad m => Monad (ReaderT tag r m) instance MonadPlus m => MonadPlus (ReaderT tag r m) instance MonadFix m => MonadFix (ReaderT tag r m) instance MonadTrans (ReaderT tag r) instance MonadIO m => MonadIO (ReaderT tag r m) instance Datatype D1ReaderT instance Constructor C1_0ReaderT instance MonadError e m => MonadError e (ReaderT tag r m) instance MonadWriter w m => MonadWriter w (ReaderT tag r m) instance MonadState s m => MonadState s (ReaderT tag r m) instance MonadReader r' m => MonadReader r' (ReaderT tag r m) instance MonadCont m => MonadCont (ReaderT tag r m) instance Tagged (ReaderT tag r m) tag instance Taggable (ReaderT tag r m) instance Newtype (ReaderT tag r m a) -- | See Control.Monad.Trans.Writer. module Control.Monad.Trans.Ether.Writer -- | The parametrizable writer monad. -- -- Computations can accumulate a monoid value. -- -- The return function produces the output mempty, while -- >>= combines the outputs of the subcomputations using -- mappend. type Writer tag w = WriterT tag w Identity -- | Constructor for computations in the writer monad (the inverse of -- runWriter). writer :: Monad m => proxy tag -> (a, w) -> WriterT tag w m a -- | Runs a Writer and returns both the normal value and the final -- accumulator. runWriter :: proxy tag -> Writer tag w a -> (a, w) -- | Runs a Writer and returns the final accumulator, discarding the -- normal value. execWriter :: proxy tag -> Writer tag w a -> w -- | The writer monad transformer. -- -- The return function produces the output mempty, while -- >>= combines the outputs of the subcomputations using -- mappend. data WriterT tag w m a -- | Constructor for computations in the writer monad transformer. writerT :: proxy tag -> m (a, w) -> WriterT tag w m a -- | Runs a WriterT and returns both the normal value and the final -- accumulator. runWriterT :: proxy tag -> WriterT tag w m a -> m (a, w) -- | Runs a WriterT and returns the final accumulator, discarding -- the normal value. execWriterT :: Monad m => proxy tag -> WriterT tag w m a -> m w -- | Transform the computation inside a WriterT. -- -- mapWriterT :: proxy tag -> (m (a, w) -> n (b, w')) -> WriterT tag w m a -> WriterT tag w' n b -- | Appends a value to the accumulator within the monad. tell :: Monad m => proxy tag -> w -> WriterT tag w m () -- | Executes an action and adds its accumulator to the value of the -- computation. listen :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m a -> WriterT tag w m (a, w) -- | Executes an action which returns a value and a function, and returns -- the value, applying the function to the accumulator. pass :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m (a, w -> w) -> WriterT tag w m a -- | Lift a callCC operation to the new monad. liftCallCC :: Monoid w => proxy tag -> CallCC m (a, w) (b, w) -> CallCC (WriterT tag w m) a b -- | Lift a catchE operation to the new monad. liftCatch :: proxy tag -> Catch e m (a, w) -> Catch e (WriterT tag w m) a -- | Lift a listen operation to the new monad. liftListen :: Monad m => proxy tag -> Listen w' m (a, w) -> Listen w' (WriterT tag w m) a -- | Lift a pass operation to the new monad. liftPass :: Monad m => proxy tag -> Pass w' m (a, w) -> Pass w' (WriterT tag w m) a instance Generic (WriterT tag w m a) instance Functor m => Functor (WriterT tag w m) instance (Applicative m, Monoid w) => Applicative (WriterT tag w m) instance (Alternative m, Monoid w) => Alternative (WriterT tag w m) instance (Monad m, Monoid w) => Monad (WriterT tag w m) instance (MonadPlus m, Monoid w) => MonadPlus (WriterT tag w m) instance (MonadFix m, Monoid w) => MonadFix (WriterT tag w m) instance Monoid w => MonadTrans (WriterT tag w) instance (Monoid w, MonadIO m) => MonadIO (WriterT tag w m) instance Datatype D1WriterT instance Constructor C1_0WriterT instance (Monoid w, MonadError e m) => MonadError e (WriterT tag w m) instance (Monoid w, MonadWriter w' m) => MonadWriter w' (WriterT tag w m) instance (Monoid w, MonadState s m) => MonadState s (WriterT tag w m) instance (Monoid w, MonadReader r m) => MonadReader r (WriterT tag w m) instance (Monoid w, MonadCont m) => MonadCont (WriterT tag w m) instance Tagged (WriterT tag w m) tag instance Taggable (WriterT tag w m) instance Newtype (WriterT tag w m a) -- | See Control.Monad.Trans.State.Lazy. module Control.Monad.Trans.Ether.State.Lazy -- | The parametrizable state monad. -- -- Computations have access to a mutable state. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as the -- initial state of the second. type State tag r = StateT tag r Identity -- | Constructor for computations in the state monad (the inverse of -- runState). state :: Monad m => proxy tag -> (s -> (a, s)) -> StateT tag s m a -- | Runs a State with the given initial state and returns both the -- final value and the final state. runState :: proxy tag -> State tag s a -> s -> (a, s) -- | Runs a State with the given initial state and returns the final -- value, discarding the final state. evalState :: proxy tag -> State tag s a -> s -> a -- | Runs a State with the given initial state and returns the final -- state, discarding the final value. execState :: proxy tag -> State tag s a -> s -> s -- | The state monad transformer. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as the -- initial state of the second. data StateT tag s m a -- | Constructor for computations in the state monad transformer. stateT :: proxy tag -> (s -> m (a, s)) -> StateT tag s m a -- | Runs a StateT with the given initial state and returns both the -- final value and the final state. runStateT :: proxy tag -> StateT tag s m a -> s -> m (a, s) -- | Runs a StateT with the given initial state and returns the -- final value, discarding the final state. evalStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m a -- | Runs a StateT with the given initial state and returns the -- final state, discarding the final value. execStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m s -- | Transform the computation inside a StateT. -- -- mapStateT :: proxy tag -> (m (a, s) -> n (b, s)) -> StateT tag s m a -> StateT tag s n b -- | Fetch the current value of the state within the monad. get :: Monad m => proxy tag -> StateT tag s m s -- | Set the value of the state within the monad. put :: Monad m => proxy tag -> s -> StateT tag s m () -- | Lift a catchE operation to the new monad. liftCatch :: proxy tag -> Catch e m (a, s) -> Catch e (StateT tag 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 uniformity property (see -- Control.Monad.Signatures). liftCallCC' :: proxy tag -> CallCC m (a, s) (b, s) -> CallCC (StateT tag s m) a b -- | Lift a listen operation to the new monad. liftListen :: Monad m => proxy tag -> Listen w m (a, s) -> Listen w (StateT tag s m) a -- | Lift a pass operation to the new monad. liftPass :: Monad m => proxy tag -> Pass w m (a, s) -> Pass w (StateT tag s m) a instance Generic (StateT tag s m a) instance Functor m => Functor (StateT tag s m) instance (Monad m, Functor m) => Applicative (StateT tag s m) instance (Functor m, MonadPlus m) => Alternative (StateT tag s m) instance Monad m => Monad (StateT tag s m) instance MonadPlus m => MonadPlus (StateT tag s m) instance MonadFix m => MonadFix (StateT tag s m) instance MonadTrans (StateT tag s) instance MonadIO m => MonadIO (StateT tag s m) instance Datatype D1StateT instance Constructor C1_0StateT instance MonadError e m => MonadError e (StateT tag s m) instance MonadWriter w m => MonadWriter w (StateT tag s m) instance MonadState s' m => MonadState s' (StateT tag s m) instance MonadReader r m => MonadReader r (StateT tag s m) instance MonadCont m => MonadCont (StateT tag s m) instance Tagged (StateT tag s m) tag instance Taggable (StateT tag s m) instance Newtype (StateT tag s m a) -- | See Control.Monad.Trans.State. module Control.Monad.Trans.Ether.State -- | See Control.Monad.Trans.State.Strict. module Control.Monad.Trans.Ether.State.Strict -- | The parametrizable state monad. -- -- Computations have access to a mutable state. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as the -- initial state of the second. type State tag r = StateT tag r Identity -- | Constructor for computations in the state monad (the inverse of -- runState). state :: Monad m => proxy tag -> (s -> (a, s)) -> StateT tag s m a -- | Runs a State with the given initial state and returns both the -- final value and the final state. runState :: proxy tag -> State tag s a -> s -> (a, s) -- | Runs a State with the given initial state and returns the final -- value, discarding the final state. evalState :: proxy tag -> State tag s a -> s -> a -- | Runs a State with the given initial state and returns the final -- state, discarding the final value. execState :: proxy tag -> State tag s a -> s -> s -- | The state monad transformer. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as the -- initial state of the second. data StateT tag s m a -- | Constructor for computations in the state monad transformer. stateT :: proxy tag -> (s -> m (a, s)) -> StateT tag s m a -- | Runs a StateT with the given initial state and returns both the -- final value and the final state. runStateT :: proxy tag -> StateT tag s m a -> s -> m (a, s) -- | Runs a StateT with the given initial state and returns the -- final value, discarding the final state. evalStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m a -- | Runs a StateT with the given initial state and returns the -- final state, discarding the final value. execStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m s -- | Transform the computation inside a StateT. -- -- mapStateT :: proxy tag -> (m (a, s) -> n (b, s)) -> StateT tag s m a -> StateT tag s n b -- | Fetch the current value of the state within the monad. get :: Monad m => proxy tag -> StateT tag s m s -- | Set the value of the state within the monad. put :: Monad m => proxy tag -> s -> StateT tag s m () -- | Lift a catchE operation to the new monad. liftCatch :: proxy tag -> Catch e m (a, s) -> Catch e (StateT tag 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 uniformity property (see -- Control.Monad.Signatures). liftCallCC' :: proxy tag -> CallCC m (a, s) (b, s) -> CallCC (StateT tag s m) a b -- | Lift a listen operation to the new monad. liftListen :: Monad m => proxy tag -> Listen w m (a, s) -> Listen w (StateT tag s m) a -- | Lift a pass operation to the new monad. liftPass :: Monad m => proxy tag -> Pass w m (a, s) -> Pass w (StateT tag s m) a instance Generic (StateT tag s m a) instance Functor m => Functor (StateT tag s m) instance (Monad m, Functor m) => Applicative (StateT tag s m) instance (Functor m, MonadPlus m) => Alternative (StateT tag s m) instance Monad m => Monad (StateT tag s m) instance MonadPlus m => MonadPlus (StateT tag s m) instance MonadFix m => MonadFix (StateT tag s m) instance MonadTrans (StateT tag s) instance MonadIO m => MonadIO (StateT tag s m) instance Datatype D1StateT instance Constructor C1_0StateT instance MonadError e m => MonadError e (StateT tag s m) instance MonadWriter w m => MonadWriter w (StateT tag s m) instance MonadState s' m => MonadState s' (StateT tag s m) instance MonadReader r m => MonadReader r (StateT tag s m) instance MonadCont m => MonadCont (StateT tag s m) instance Tagged (StateT tag s m) tag instance Taggable (StateT tag s m) instance Newtype (StateT tag s m a) -- | See Control.Monad.Trans.Except. module Control.Monad.Trans.Ether.Except -- | The parameterizable exception monad. -- -- Computations are either exceptions or normal values. -- -- The return function returns a normal value, while -- >>= exits on the first exception. type Except tag e = ExceptT tag e Identity -- | Constructor for computations in the exception monad (the inverse of -- runExcept). except :: Monad m => proxy tag -> Either e a -> ExceptT tag e m a -- | Runs an Except and returns either an exception or a normal -- value. runExcept :: proxy tag -> Except tag e a -> Either e a -- | The exception monad transformer. -- -- The return function returns a normal value, while -- >>= exits on the first exception. data ExceptT tag e m a -- | Constructor for computations in the exception monad transformer. exceptT :: proxy tag -> m (Either e a) -> ExceptT tag e m a -- | Runs an ExceptT and returns either an exception or a normal -- value. runExceptT :: proxy tag -> ExceptT tag e m a -> m (Either e a) -- | Transforms the computation inside an ExceptT. -- -- mapExceptT :: proxy tag -> (m (Either e a) -> n (Either e' b)) -> ExceptT tag e m a -> ExceptT tag e' n b -- | Is used within a monadic computation to begin exception processing. throw :: Monad m => proxy tag -> e -> ExceptT tag e m a -- | A handler function to handle previous exceptions and return to normal -- execution. catch :: Monad m => proxy tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a -- | Lift a callCC operation to the new monad. liftCallCC :: proxy tag -> CallCC m (Either e a) (Either e b) -> CallCC (ExceptT tag e m) a b -- | Lift a listen operation to the new monad. liftListen :: Monad m => proxy tag -> Listen w m (Either e a) -> Listen w (ExceptT tag e m) a -- | Lift a pass operation to the new monad. liftPass :: Monad m => proxy tag -> Pass w m (Either e a) -> Pass w (ExceptT tag e m) a -- | Lift a catchE operation to the new monad. liftCatch :: proxy tag -> Catch e m (Either e' a) -> Catch e (ExceptT tag e' m) a instance Generic (ExceptT tag e m a) instance Functor m => Functor (ExceptT tag e m) instance (Monad m, Functor m) => Applicative (ExceptT tag e m) instance (Monad m, Functor m, Monoid e) => Alternative (ExceptT tag e m) instance Monad m => Monad (ExceptT tag e m) instance (Monad m, Monoid e) => MonadPlus (ExceptT tag e m) instance MonadFix m => MonadFix (ExceptT tag e m) instance MonadTrans (ExceptT tag e) instance MonadIO m => MonadIO (ExceptT tag e m) instance Datatype D1ExceptT instance Constructor C1_0ExceptT instance MonadError e' m => MonadError e' (ExceptT tag e m) instance MonadWriter w m => MonadWriter w (ExceptT tag e m) instance MonadState s m => MonadState s (ExceptT tag e m) instance MonadReader r m => MonadReader r (ExceptT tag e m) instance MonadCont m => MonadCont (ExceptT tag e m) instance Tagged (ExceptT tag e m) tag instance Taggable (ExceptT tag e m) instance Newtype (ExceptT tag e m a) -- | See Control.Monad.Reader.Class. module Control.Monad.Ether.Reader.Class -- | See MonadReader. class Monad m => MonadReader tag r m | m tag -> r where ask t = reader t id reader t f = fmap f (ask t) ask :: MonadReader tag r m => proxy tag -> m r local :: MonadReader tag r m => proxy tag -> (r -> r) -> m a -> m a reader :: MonadReader tag r m => proxy tag -> (r -> a) -> m a -- | Retrieves a function of the current environment. asks :: MonadReader tag r m => proxy tag -> (r -> a) -> m a instance [overlap ok] (Monoid w, MonadReader tag r m) => MonadReader tag r (WriterT w m) instance [overlap ok] (Monoid w, MonadReader tag r m) => MonadReader tag r (WriterT w m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (StateT s m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (StateT s m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (ReaderT r' m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (MaybeT m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (ListT m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (IdentityT m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (ExceptT e m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (ContT r' m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (ExceptT tag' e m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (StateT tag' s m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (StateT tag' s m) instance [overlap ok] (Monoid w, MonadReader tag r m) => MonadReader tag r (WriterT tag' w m) instance [overlap ok] MonadReader tag r m => MonadReader tag r (ReaderT tag' r' m) instance [overlap ok] Monad m => MonadReader tag r (ReaderT tag r m) -- | See Control.Monad.Reader. module Control.Monad.Ether.Reader -- | See MonadReader. class Monad m => MonadReader tag r m | m tag -> r where ask t = reader t id reader t f = fmap f (ask t) ask :: MonadReader tag r m => proxy tag -> m r local :: MonadReader tag r m => proxy tag -> (r -> r) -> m a -> m a reader :: MonadReader tag r m => proxy tag -> (r -> a) -> m a -- | Retrieves a function of the current environment. asks :: MonadReader tag r m => proxy tag -> (r -> a) -> m a -- | 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 tag r = ReaderT tag r Identity -- | Runs a ReaderT with the given environment and returns the vinal -- value. runReader :: proxy tag -> Reader tag r a -> 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. data ReaderT tag r m a -- | Constructor for computations in the reader monad transformer. readerT :: proxy tag -> (r -> m a) -> ReaderT tag r m a -- | Runs a ReaderT with the given environment and returns the vinal -- value. runReaderT :: proxy tag -> ReaderT tag r m a -> r -> m a -- | Transform the computation inside a ReaderT. -- -- mapReaderT :: proxy tag -> (m a -> n b) -> ReaderT tag r m a -> ReaderT tag r n b -- | See Control.Monad.Ether.Reader. module Control.Monad.Ether.Implicit.Reader -- | See MonadReader. type MonadReader r = MonadReader r r -- | See local. local :: MonadReader r m => (r -> r) -> m a -> m a -- | See ask. ask :: MonadReader r m => m r -- | See reader. reader :: MonadReader r m => (r -> a) -> m a -- | See asks. asks :: MonadReader r m => (r -> a) -> m a -- | See Reader. type Reader r = Reader r r -- | See runReader. runReader :: Reader r a -> r -> a -- | See ReaderT. type ReaderT r = ReaderT r r -- | See readerT. readerT :: (r -> m a) -> ReaderT r m a -- | See runReaderT. runReaderT :: ReaderT r m a -> r -> m a -- | See mapReaderT. mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b -- | See Control.Monad.State.Class. module Control.Monad.Ether.State.Class -- | See MonadState. class Monad m => MonadState tag s m | m tag -> s where get t = state t (\ s -> (s, s)) put t s = state t (\ _ -> ((), s)) state t f = do { s <- get t; let ~(a, s') = f s; put t s'; return a } get :: MonadState tag s m => proxy tag -> m s put :: MonadState tag s m => proxy tag -> s -> m () state :: MonadState tag s m => proxy tag -> (s -> (a, s)) -> m a -- | Modifies the state inside a state monad. modify :: MonadState tag s m => proxy tag -> (s -> s) -> m () -- | Gets specific component of the state, using a projection function -- supplied. gets :: MonadState tag s m => proxy tag -> (s -> a) -> m a instance [overlap ok] (Monoid w, MonadState tag s m) => MonadState tag s (WriterT w m) instance [overlap ok] (Monoid w, MonadState tag s m) => MonadState tag s (WriterT w m) instance [overlap ok] MonadState tag s m => MonadState tag s (StateT s' m) instance [overlap ok] MonadState tag s m => MonadState tag s (StateT s' m) instance [overlap ok] MonadState tag s m => MonadState tag s (ReaderT r m) instance [overlap ok] MonadState tag s m => MonadState tag s (MaybeT m) instance [overlap ok] MonadState tag s m => MonadState tag s (ListT m) instance [overlap ok] MonadState tag s m => MonadState tag s (IdentityT m) instance [overlap ok] MonadState tag s m => MonadState tag s (ExceptT e m) instance [overlap ok] MonadState tag s m => MonadState tag s (ContT r m) instance [overlap ok] MonadState tag s m => MonadState tag s (ExceptT tag' e m) instance [overlap ok] (Monoid w, MonadState tag s m) => MonadState tag s (WriterT tag' w m) instance [overlap ok] MonadState tag s m => MonadState tag s (ReaderT tag' r m) instance [overlap ok] MonadState tag s m => MonadState tag s (StateT tag' s' m) instance [overlap ok] Monad m => MonadState tag s (StateT tag s m) instance [overlap ok] MonadState tag s m => MonadState tag s (StateT tag' s' m) instance [overlap ok] Monad m => MonadState tag s (StateT tag s m) -- | See Control.Monad.State.Lazy. module Control.Monad.Ether.State.Lazy -- | See MonadState. class Monad m => MonadState tag s m | m tag -> s where get t = state t (\ s -> (s, s)) put t s = state t (\ _ -> ((), s)) state t f = do { s <- get t; let ~(a, s') = f s; put t s'; return a } get :: MonadState tag s m => proxy tag -> m s put :: MonadState tag s m => proxy tag -> s -> m () state :: MonadState tag s m => proxy tag -> (s -> (a, s)) -> m a -- | Modifies the state inside a state monad. modify :: MonadState tag s m => proxy tag -> (s -> s) -> m () -- | Gets specific component of the state, using a projection function -- supplied. gets :: MonadState tag s m => proxy tag -> (s -> a) -> m a -- | The parametrizable state monad. -- -- Computations have access to a mutable state. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as the -- initial state of the second. type State tag r = StateT tag r Identity -- | Runs a State with the given initial state and returns both the -- final value and the final state. runState :: proxy tag -> State tag s a -> s -> (a, s) -- | Runs a State with the given initial state and returns the final -- value, discarding the final state. evalState :: proxy tag -> State tag s a -> s -> a -- | Runs a State with the given initial state and returns the final -- state, discarding the final value. execState :: proxy tag -> State tag s a -> s -> s -- | The state monad transformer. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as the -- initial state of the second. data StateT tag s m a -- | Constructor for computations in the state monad transformer. stateT :: proxy tag -> (s -> m (a, s)) -> StateT tag s m a -- | Runs a StateT with the given initial state and returns both the -- final value and the final state. runStateT :: proxy tag -> StateT tag s m a -> s -> m (a, s) -- | Runs a StateT with the given initial state and returns the -- final value, discarding the final state. evalStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m a -- | Runs a StateT with the given initial state and returns the -- final state, discarding the final value. execStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m s -- | Transform the computation inside a StateT. -- -- mapStateT :: proxy tag -> (m (a, s) -> n (b, s)) -> StateT tag s m a -> StateT tag s n b -- | See Control.Monad.State. module Control.Monad.Ether.State -- | See Control.Monad.Ether.State.Lazy. module Control.Monad.Ether.Implicit.State.Lazy -- | See MonadState. type MonadState s = MonadState s s -- | See get. get :: MonadState s m => m s -- | See put. put :: MonadState s m => s -> m () -- | See state. state :: MonadState s m => (s -> (a, s)) -> m a -- | See modify. modify :: MonadState s m => (s -> s) -> m () -- | See gets. gets :: MonadState s m => (s -> a) -> m a -- | See State. type State s = State s s -- | See runState. runState :: State s a -> s -> (a, s) -- | See evalState. evalState :: State s a -> s -> a -- | See execState. execState :: State s a -> s -> s -- | See StateT. type StateT s = StateT s s -- | See stateT. stateT :: (s -> m (a, s)) -> StateT s m a -- | See runStateT. runStateT :: StateT s m a -> s -> m (a, s) -- | See evalStateT. evalStateT :: Monad m => StateT s m a -> s -> m a -- | See execStateT. execStateT :: Monad m => StateT s m a -> s -> m s -- | See mapStateT. mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b -- | See Control.Monad.Ether.State. module Control.Monad.Ether.Implicit.State -- | See Control.Monad.State.Strict. module Control.Monad.Ether.State.Strict -- | See MonadState. class Monad m => MonadState tag s m | m tag -> s where get t = state t (\ s -> (s, s)) put t s = state t (\ _ -> ((), s)) state t f = do { s <- get t; let ~(a, s') = f s; put t s'; return a } get :: MonadState tag s m => proxy tag -> m s put :: MonadState tag s m => proxy tag -> s -> m () state :: MonadState tag s m => proxy tag -> (s -> (a, s)) -> m a -- | Modifies the state inside a state monad. modify :: MonadState tag s m => proxy tag -> (s -> s) -> m () -- | Gets specific component of the state, using a projection function -- supplied. gets :: MonadState tag s m => proxy tag -> (s -> a) -> m a -- | The parametrizable state monad. -- -- Computations have access to a mutable state. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as the -- initial state of the second. type State tag r = StateT tag r Identity -- | Runs a State with the given initial state and returns both the -- final value and the final state. runState :: proxy tag -> State tag s a -> s -> (a, s) -- | Runs a State with the given initial state and returns the final -- value, discarding the final state. evalState :: proxy tag -> State tag s a -> s -> a -- | Runs a State with the given initial state and returns the final -- state, discarding the final value. execState :: proxy tag -> State tag s a -> s -> s -- | The state monad transformer. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as the -- initial state of the second. data StateT tag s m a -- | Constructor for computations in the state monad transformer. stateT :: proxy tag -> (s -> m (a, s)) -> StateT tag s m a -- | Runs a StateT with the given initial state and returns both the -- final value and the final state. runStateT :: proxy tag -> StateT tag s m a -> s -> m (a, s) -- | Runs a StateT with the given initial state and returns the -- final value, discarding the final state. evalStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m a -- | Runs a StateT with the given initial state and returns the -- final state, discarding the final value. execStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m s -- | Transform the computation inside a StateT. -- -- mapStateT :: proxy tag -> (m (a, s) -> n (b, s)) -> StateT tag s m a -> StateT tag s n b -- | See Control.Monad.Ether.State.Strict. module Control.Monad.Ether.Implicit.State.Strict -- | See MonadState. type MonadState s = MonadState s s -- | See get. get :: MonadState s m => m s -- | See put. put :: MonadState s m => s -> m () -- | See state. state :: MonadState s m => (s -> (a, s)) -> m a -- | See modify. modify :: MonadState s m => (s -> s) -> m () -- | See gets. gets :: MonadState s m => (s -> a) -> m a -- | See State. type State s = State s s -- | See runState. runState :: State s a -> s -> (a, s) -- | See evalState. evalState :: State s a -> s -> a -- | See execState. execState :: State s a -> s -> s -- | See StateT. type StateT s = StateT s s -- | See stateT. stateT :: (s -> m (a, s)) -> StateT s m a -- | See runStateT. runStateT :: StateT s m a -> s -> m (a, s) -- | See evalStateT. evalStateT :: Monad m => StateT s m a -> s -> m a -- | See execStateT. execStateT :: Monad m => StateT s m a -> s -> m s -- | See mapStateT. mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b -- | See Control.Monad.Except. module Control.Monad.Ether.Except.Class -- | See MonadError. class Monad m => MonadExcept tag e m | m tag -> e throw :: MonadExcept tag e m => proxy tag -> e -> m a catch :: MonadExcept tag e m => proxy tag -> m a -> (e -> m a) -> m a instance [overlap ok] (Monoid w, MonadExcept tag e m) => MonadExcept tag e (WriterT w m) instance [overlap ok] (Monoid w, MonadExcept tag e m) => MonadExcept tag e (WriterT w m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (StateT s m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (StateT s m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (ReaderT r m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (MaybeT m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (ListT m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (IdentityT m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (ExceptT e' m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (StateT tag' s m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (StateT tag' s m) instance [overlap ok] (Monoid w, MonadExcept tag e m) => MonadExcept tag e (WriterT tag' w m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (ReaderT tag' r m) instance [overlap ok] MonadExcept tag e m => MonadExcept tag e (ExceptT tag' e' m) instance [overlap ok] Monad m => MonadExcept tag e (ExceptT tag e m) -- | See Control.Monad.Except. module Control.Monad.Ether.Except -- | See MonadError. class Monad m => MonadExcept tag e m | m tag -> e throw :: MonadExcept tag e m => proxy tag -> e -> m a catch :: MonadExcept tag e m => proxy tag -> m a -> (e -> m a) -> m a -- | The parameterizable exception monad. -- -- Computations are either exceptions or normal values. -- -- The return function returns a normal value, while -- >>= exits on the first exception. type Except tag e = ExceptT tag e Identity -- | Runs an Except and returns either an exception or a normal -- value. runExcept :: proxy tag -> Except tag e a -> Either e a -- | The exception monad transformer. -- -- The return function returns a normal value, while -- >>= exits on the first exception. data ExceptT tag e m a -- | Constructor for computations in the exception monad transformer. exceptT :: proxy tag -> m (Either e a) -> ExceptT tag e m a -- | Runs an ExceptT and returns either an exception or a normal -- value. runExceptT :: proxy tag -> ExceptT tag e m a -> m (Either e a) -- | Transforms the computation inside an ExceptT. -- -- mapExceptT :: proxy tag -> (m (Either e a) -> n (Either e' b)) -> ExceptT tag e m a -> ExceptT tag e' n b -- | Runs an ExceptT and handles the exception with the given -- function. handleT :: Functor m => proxy tag -> (e -> a) -> ExceptT tag e m a -> m a -- | Runs an Except and handles the exception with the given -- function. handle :: proxy tag -> (e -> a) -> Except tag e a -> a -- | See Control.Monad.Ether.Except. module Control.Monad.Ether.Implicit.Except -- | See MonadExcept. type MonadExcept e = MonadExcept e e -- | See throw. throw :: MonadExcept e m => e -> m a -- | See catch. catch :: MonadExcept e m => m a -> (e -> m a) -> m a -- | See Except. type Except e = Except e e -- | See runExcept. runExcept :: Except e a -> Either e a -- | See ExceptT. type ExceptT e = ExceptT e e -- | See exceptT. exceptT :: m (Either e a) -> ExceptT e m a -- | See runExceptT. runExceptT :: ExceptT e m a -> m (Either e a) -- | See mapExceptT. Note that due to implicit tagging the exception -- type cannot be changed. mapExceptT :: (m (Either e a) -> n (Either e b)) -> ExceptT e m a -> ExceptT e n b -- | See handle. handle :: (e -> a) -> Except e a -> a -- | See handleT. handleT :: Functor m => (e -> a) -> ExceptT e m a -> m a -- | See Control.Monad.Writer.Class. module Control.Monad.Ether.Writer.Class -- | See MonadWriter. class (Monoid w, Monad m) => MonadWriter tag w m | m tag -> w where writer t ~(a, w) = do { tell t w; return a } tell t w = writer t ((), w) writer :: MonadWriter tag w m => proxy tag -> (a, w) -> m a tell :: MonadWriter tag w m => proxy tag -> w -> m () listen :: MonadWriter tag w m => proxy tag -> m a -> m (a, w) pass :: MonadWriter tag w m => proxy tag -> m (a, w -> w) -> m a -- | Execute an action and add the result of applying the given function to -- its accumulator to the value of the computation. listens :: MonadWriter tag w m => proxy tag -> (w -> b) -> m a -> m (a, b) -- | Execute an action and apply a function to its accumulator. censor :: MonadWriter tag w m => proxy tag -> (w -> w) -> m a -> m a instance [overlap ok] (Monoid w', MonadWriter tag w m) => MonadWriter tag w (WriterT w' m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (StateT s m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (StateT s m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (ReaderT r m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (MaybeT m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (IdentityT m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (ExceptT e m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (StateT tag' e m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (StateT tag' e m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (ExceptT tag' e m) instance [overlap ok] MonadWriter tag w m => MonadWriter tag w (ReaderT tag' r m) instance [overlap ok] (Monoid w', MonadWriter tag w m) => MonadWriter tag w (WriterT tag' w' m) instance [overlap ok] (Monoid w, Monad m) => MonadWriter tag w (WriterT tag w m) -- | Annotating monads with tags to turn untagged constraints into tagged -- ones. -- --
--   import qualified Control.Monad.State as T
--   import Control.Ether.TH (ethereal)
--   import Control.Monad.Ether.State (MonadState)
--   import Control.Ether.Wrapped (ethered)
--   
--   ethereal "Foo" "foo"
--   
--   f :: T.MonadState Int m => m String
--   f = fmap show T.get
--   
--   g :: MonadState Foo Int m => m String
--   g = ethered foo f
--   
module Control.Ether.Wrapped -- | Wrap a monad to attach a tag to it. newtype WrappedEther tag m a WrapEther :: m a -> WrappedEther tag m a unwrapEther :: WrappedEther tag m a -> m a -- | Annotate a polymorphic monadic computation with a tag. ethered :: proxy tag -> WrappedEther tag m a -> m a instance Functor m => Functor (WrappedEther tag m) instance Applicative m => Applicative (WrappedEther tag m) instance Alternative m => Alternative (WrappedEther tag m) instance Monad m => Monad (WrappedEther tag m) instance MonadPlus m => MonadPlus (WrappedEther tag m) instance MonadFix m => MonadFix (WrappedEther tag m) instance MonadIO m => MonadIO (WrappedEther tag m) instance MonadWriter tag w m => MonadWriter tag w (WrappedEther tag' m) instance MonadWriter tag w m => MonadWriter w (WrappedEther tag m) instance MonadExcept tag e m => MonadExcept tag e (WrappedEther tag' m) instance MonadExcept tag e m => MonadError e (WrappedEther tag m) instance MonadState tag s m => MonadState tag s (WrappedEther tag' m) instance MonadState tag s m => MonadState s (WrappedEther tag m) instance MonadReader tag r m => MonadReader tag r (WrappedEther tag' m) instance MonadReader tag r m => MonadReader r (WrappedEther tag m) -- | See Control.Monad.Writer. module Control.Monad.Ether.Writer -- | See MonadWriter. class (Monoid w, Monad m) => MonadWriter tag w m | m tag -> w where writer t ~(a, w) = do { tell t w; return a } tell t w = writer t ((), w) writer :: MonadWriter tag w m => proxy tag -> (a, w) -> m a tell :: MonadWriter tag w m => proxy tag -> w -> m () listen :: MonadWriter tag w m => proxy tag -> m a -> m (a, w) pass :: MonadWriter tag w m => proxy tag -> m (a, w -> w) -> m a -- | Execute an action and add the result of applying the given function to -- its accumulator to the value of the computation. listens :: MonadWriter tag w m => proxy tag -> (w -> b) -> m a -> m (a, b) -- | Execute an action and apply a function to its accumulator. censor :: MonadWriter tag w m => proxy tag -> (w -> w) -> m a -> m a -- | The parametrizable writer monad. -- -- Computations can accumulate a monoid value. -- -- The return function produces the output mempty, while -- >>= combines the outputs of the subcomputations using -- mappend. type Writer tag w = WriterT tag w Identity -- | Runs a Writer and returns both the normal value and the final -- accumulator. runWriter :: proxy tag -> Writer tag w a -> (a, w) -- | Runs a Writer and returns the final accumulator, discarding the -- normal value. execWriter :: proxy tag -> Writer tag w a -> w -- | The writer monad transformer. -- -- The return function produces the output mempty, while -- >>= combines the outputs of the subcomputations using -- mappend. data WriterT tag w m a -- | Constructor for computations in the writer monad transformer. writerT :: proxy tag -> m (a, w) -> WriterT tag w m a -- | Runs a WriterT and returns both the normal value and the final -- accumulator. runWriterT :: proxy tag -> WriterT tag w m a -> m (a, w) -- | Runs a WriterT and returns the final accumulator, discarding -- the normal value. execWriterT :: Monad m => proxy tag -> WriterT tag w m a -> m w -- | Transform the computation inside a WriterT. -- -- mapWriterT :: proxy tag -> (m (a, w) -> n (b, w')) -> WriterT tag w m a -> WriterT tag w' n b -- | This module provides convenience exports of all tagged monad classes -- from Ether. module Control.Monad.Ether -- | Creates a tag and a value-level proxy for it. -- -- ethereal "Foo" "foo" generates the following code: -- --
--   data Foo
--   foo :: Proxy Foo
--   foo = Proxy
--   
ethereal :: String -> String -> DecsQ -- | Abbreviations for constraints. module Control.Ether.Abbr -- | Denotes MonadReader. The mnemonic is that you read values of -- type r from the reader environment tagged by tag, -- thus the arrows points from tag to r. data (-->) tag r -- | Denotes MonadWriter. The mnemonic is that you write values of -- w to the writer accumulator tagged by tag, thus the -- arrows points from w to tag. data (<--) tag w -- | Denotes MonadState. The mnemonic is that you can both read from -- and write into the state, thus the arrow points in both directions. data (<->) tag s -- | Denotes MonadExcept. data (-!-) tag e -- | Reify a list of constraint abbreviations. -- --
--   f :: Ether '[Foo --> r, Bar <-- w, Baz <-> s, Quux -!- e] m => m a
--   
-- -- expands into -- --
--   f :: ( MonadReader Foo  r m
--        , MonadWriter Bar  w m
--        , MonadState  Baz  s m
--        , MonadExcept Quux e m
--        ) => m a
--   
-- | Turns an abbreviation into an actual constraint. -- | See Control.Monad.Ether.Writer. module Control.Monad.Ether.Implicit.Writer -- | See MonadWriter. type MonadWriter w = MonadWriter w w -- | See writer. writer :: MonadWriter w m => (a, w) -> m a -- | See tell. tell :: MonadWriter w m => w -> m () -- | See listen. listen :: MonadWriter w m => m a -> m (a, w) -- | See pass. pass :: MonadWriter w m => m (a, w -> w) -> m a -- | See listens. listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b) -- | See censor. censor :: MonadWriter w m => (w -> w) -> m a -> m a -- | See Writer. type Writer w = Writer w w -- | See runWriter. runWriter :: Writer w a -> (a, w) -- | See execWriter. execWriter :: Writer w a -> w -- | See WriterT. type WriterT w = WriterT w w -- | See writerT. writerT :: m (a, w) -> WriterT w m a -- | See runWriterT. runWriterT :: WriterT w m a -> m (a, w) -- | See execWriterT. execWriterT :: Monad m => WriterT w m a -> m w -- | This module provides convenience exports of all implicitly tagged -- monad classes from Ether. module Control.Monad.Ether.Implicit -- | See Control.Ether.Abbr. module Control.Ether.Implicit.Abbr -- | Denotes MonadReader. data R r -- | Denotes MonadWriter. data W w -- | Denotes MonadState. data S s -- | Denotes MonadExcept. data E e