-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Allocate resources which are guaranteed to be released.
--
-- This is a simplified, standalone version of the ResourceT
-- transformer that was originally developed as part of the
-- conduit package. That version of ResourceT was
-- supported by a complicated hierarchy of type classes, the main purpose
-- of which was to enable the usage of ResourceT on top of the
-- ST monad. However, this doesn't really make much sense
-- conceptually, and the reason it was done is because conduits are very
-- closely tied to ResourceT, and an instance for ST
-- would enable the usage of ResourceT in pure code.
--
-- This package completely does away with the supporting type class
-- hierarchy, and as such, this version of ResourceT can only be
-- used with IO or IO-like monads.
--
-- This package is motivated by a belief that the iteratee problem and
-- the resource finalization problem are orthogonal. This package is
-- ideal for usage with the pipes library.
@package resource-simple
@version 0.1
-- | Allocate resources which are guaranteed to be released.
--
-- One point to note: all register cleanup actions live in IO, not the
-- main monad. This allows both more efficient code, and for monads to be
-- transformed.
module Control.Monad.Resource
-- | The Resource transformer. This transformer keeps track of all
-- registered actions, and calls them upon exit (via
-- runResourceT). Actions may be registered via register,
-- or resources may be allocated atomically via with. The with
-- function corresponds closely to bracket.
--
-- Releasing may be performed before exit via the release
-- function. This is a highly recommended optimization, as it will ensure
-- that scarce resources are freed early. Note that calling
-- release will deregister the action, so that a release action
-- will only ever be called once.
data ResourceT m a
-- | A lookup key for a specific release action. This value is returned by
-- register and with and is passed to release.
data ReleaseKey
-- | Unwrap a ResourceT transformer, and call all registered release
-- actions.
--
-- Note that there is some reference counting involved due to the
-- MonadFork instance. If multiple threads are sharing the same
-- collection of resources, only the last call to runResourceT
-- will deallocate the resources.
runResourceT :: MonadBaseControl IO m => ResourceT m a -> m a
-- | Perform some allocation, and automatically register a cleanup action.
with :: MonadBase IO m => IO a -> (a -> IO ()) -> ResourceT m (ReleaseKey, a)
-- | Register some action that will be called precisely once, either when
-- runResourceT is called, or when the ReleaseKey is passed
-- to release.
register :: MonadBase IO m => IO () -> ResourceT m ReleaseKey
-- | Call a release action early, and deregister it from the list of
-- cleanup actions to be performed.
release :: MonadBase IO m => ReleaseKey -> ResourceT m ()
-- | Transform the monad a ResourceT lives in. This is most often
-- used to strip or add new transformers to a stack, e.g. to run a
-- ReaderT.
transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b
instance MonadWriter w m => MonadWriter w (ResourceT m)
instance MonadState s m => MonadState s (ResourceT m)
instance MonadRWS r w s m => MonadRWS r w s (ResourceT m)
instance MonadReader r m => MonadReader r (ResourceT m)
instance MonadError e m => MonadError e (ResourceT m)
instance MonadCont m => MonadCont (ResourceT m)
instance (MonadFork m, MonadBaseControl IO m) => MonadFork (ResourceT m)
instance MonadBaseControl b m => MonadBaseControl b (ResourceT m)
instance MonadBase b m => MonadBase b (ResourceT m)
instance MonadIO m => MonadIO (ResourceT m)
instance Monad m => Monad (ResourceT m)
instance Applicative m => Applicative (ResourceT m)
instance Functor m => Functor (ResourceT m)
instance MonadTransControl ResourceT
instance MonadTrans ResourceT