-- 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.2 -- | 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. These -- functions are provided by 'ResourceT'\'s MonadResource -- instance. -- -- 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. -- -- Pass-through instances for the mtl type classes are provided -- automatically by the mtl-evil-instances package. data ResourceT m a -- | Unwrap a ResourceT transformer, and call all registered release -- actions. -- -- Note that there is some reference counting involved due to the -- implementation of fork used in 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 -- | 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. mapResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b -- | The MonadResource type class. This provides the with, -- register and release functions, which are the main -- functionality of this package. The main instance of this class is -- ResourceT. -- -- The others instances are overlapping instances (in the spirit of -- mtl-evil-instances), which provide automatic pass-through -- instances for MonadResource for every monad transformer. This -- means that you don't have to provide a pass-through instance of -- MonadResource for every monad transformer you write. class MonadIO m => MonadResource m with :: MonadResource m => IO a -> (a -> IO ()) -> m (ReleaseKey, a) register :: MonadResource m => IO () -> m ReleaseKey release :: MonadResource m => ReleaseKey -> m () -- | A lookup key for a specific release action. This value is returned by -- register and with and is passed to release. data ReleaseKey instance [overlap ok] (MonadBase b m, MonadResource b) => MonadResource m instance [overlap ok] (MonadTrans t, Monad (t m), MonadResource m) => MonadResource (t m) instance [overlap ok] MonadBaseControl IO m => MonadResource (ResourceT m) instance [overlap ok] (MonadFork m, MonadBaseControl IO m) => MonadFork (ResourceT m) instance [overlap ok] MonadBaseControl b m => MonadBaseControl b (ResourceT m) instance [overlap ok] MonadPlus m => MonadPlus (ResourceT m) instance [overlap ok] Monad m => Monad (ResourceT m) instance [overlap ok] MonadPlus m => Alternative (ResourceT m) instance [overlap ok] Monad m => Applicative (ResourceT m) instance [overlap ok] Monad m => Functor (ResourceT m) instance [overlap ok] MonadTransControl ResourceT instance [overlap ok] MonadTrans ResourceT