<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Control.Monad.Trans.Resource</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_Control-Monad-Trans-Resource.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Control-Monad-Trans-Resource.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">conduit-0.2.2: Streaming data processing library.</p></div><div id="content"><div id="module-header"><p class="caption">Control.Monad.Trans.Resource</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Data types </a></li><li><a href="#g:2">Unwrap </a></li><li><a href="#g:3">Resource allocation </a></li><li><a href="#g:4">Use references </a></li><li><a href="#g:5">Special actions </a></li><li><a href="#g:6">Monad transformation </a></li><li><a href="#g:7">A specific Exception transformer </a></li><li><a href="#g:8">Type class/associated types </a><ul><li><a href="#g:9">Low-level </a></li></ul></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Allocate resources which are guaranteed to be released. </p><p>For more information, see <a href="http://www.yesodweb.com/blog/2011/12/resourcet">http://www.yesodweb.com/blog/2011/12/resourcet</a>. </p><p>One point to note: all register cleanup actions live in the base monad, not the main monad. This allows both more efficient code, and for monads to be transformed. </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:ResourceT">ResourceT</a> m a</li><li class="src short"><span class="keyword">data</span> <a href="#t:ReleaseKey">ReleaseKey</a> </li><li class="src short"><a href="#v:runResourceT">runResourceT</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m a -> m a</li><li class="src short"><a href="#v:with">with</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m a -> (a -> <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>) -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m (<a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a>, a)</li><li class="src short"><a href="#v:withIO">withIO</a> :: <a href="Control-Monad-Trans-Resource.html#t:ResourceIO">ResourceIO</a> m => <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a -> (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>) -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m (<a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a>, a)</li><li class="src short"><a href="#v:register">register</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a></li><li class="src short"><a href="#v:release">release</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a> -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:readRef">readRef</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m) a -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m a</li><li class="src short"><a href="#v:writeRef">writeRef</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m) a -> a -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:newRef">newRef</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => a -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m (<a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m) a)</li><li class="src short"><a href="#v:resourceForkIO">resourceForkIO</a> :: <a href="Control-Monad-Trans-Resource.html#t:ResourceIO">ResourceIO</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Concurrent.html#t:ThreadId">ThreadId</a></li><li class="src short"><a href="#v:transResourceT">transResourceT</a> :: <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m ~ <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> n => (m a -> n b) -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m a -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> n b</li><li class="src short"><span class="keyword">newtype</span> <a href="#t:ExceptionT">ExceptionT</a> m a = <a href="#v:ExceptionT">ExceptionT</a> {<ul class="subs"><li><a href="#v:runExceptionT">runExceptionT</a> :: m (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Either.html#t:Either">Either</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a> a)</li></ul>}</li><li class="src short"><a href="#v:runExceptionT_">runExceptionT_</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m a -> m a</li><li class="src short"><span class="keyword">class</span> (<a href="Control-Monad-Trans-Resource.html#t:HasRef">HasRef</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m), <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m) => <a href="#t:Resource">Resource</a> m <span class="keyword">where</span><ul class="subs"><li><span class="keyword">type</span> <a href="#t:Base">Base</a> m :: * -> *</li><li><a href="#v:resourceLiftBase">resourceLiftBase</a> :: <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m a -> m a</li><li><a href="#v:resourceBracket_">resourceBracket_</a> :: <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> m c -> m c</li></ul></li><li class="src short"><span class="keyword">class</span> <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="#t:ResourceUnsafeIO">ResourceUnsafeIO</a> m <span class="keyword">where</span><ul class="subs"><li><a href="#v:unsafeFromIO">unsafeFromIO</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a -> m a</li></ul></li><li class="src short"><span class="keyword">class</span> (<a href="Control-Monad-Trans-Resource.html#t:ResourceBaseIO">ResourceBaseIO</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m), <a href="Control-Monad-Trans-Resource.html#t:ResourceUnsafeIO">ResourceUnsafeIO</a> m, <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m, <a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> m, <a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> m) => <a href="#t:ResourceIO">ResourceIO</a> m </li><li class="src short"><span class="keyword">class</span> <a href="#t:ResourceBaseIO">ResourceBaseIO</a> m <span class="keyword">where</span><ul class="subs"><li><a href="#v:safeFromIOBase">safeFromIOBase</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a -> m a</li></ul></li><li class="src short"><span class="keyword">class</span> <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="#t:ResourceThrow">ResourceThrow</a> m <span class="keyword">where</span><ul class="subs"><li><a href="#v:resourceThrow">resourceThrow</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Exception-Base.html#t:Exception">Exception</a> e => e -> m a</li></ul></li><li class="src short"><span class="keyword">class</span> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="#t:HasRef">HasRef</a> m <span class="keyword">where</span><ul class="subs"><li><span class="keyword">type</span> <a href="#t:Ref">Ref</a> m :: * -> *</li><li><a href="#v:newRef-39-">newRef'</a> :: a -> m (<a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> m a)</li><li><a href="#v:readRef-39-">readRef'</a> :: <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> m a -> m a</li><li><a href="#v:writeRef-39-">writeRef'</a> :: <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> m a -> a -> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li><a href="#v:atomicModifyRef-39-">atomicModifyRef'</a> :: <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> m a -> (a -> (a, b)) -> m b</li><li><a href="#v:mask">mask</a> :: ((<span class="keyword">forall</span> a. m a -> m a) -> m b) -> m b</li><li><a href="#v:mask_">mask_</a> :: m a -> m a</li><li><a href="#v:try">try</a> :: m a -> m (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Either.html#t:Either">Either</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a> a)</li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:InvalidAccess">InvalidAccess</a> = <a href="#v:InvalidAccess">InvalidAccess</a> {<ul class="subs"><li><a href="#v:functionName">functionName</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Char.html#t:String">String</a></li></ul>}</li><li class="src short"><a href="#v:resourceActive">resourceActive</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a></li></ul></div><div id="interface"><h1 id="g:1">Data types </h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:ResourceT" class="def">ResourceT</a> m a <a href="src/Control-Monad-Trans-Resource.html#ResourceT" class="link">Source</a></p><div class="doc"><p>The Resource transformer. This transformer keeps track of all registered actions, and calls them upon exit (via <code><a href="Control-Monad-Trans-Resource.html#v:runResourceT">runResourceT</a></code>). Actions may be registered via <code><a href="Control-Monad-Trans-Resource.html#v:register">register</a></code>, or resources may be allocated atomically via <code><a href="Control-Monad-Trans-Resource.html#v:with">with</a></code> or <code><a href="Control-Monad-Trans-Resource.html#v:withIO">withIO</a></code>. The with functions correspond closely to <code>bracket</code>. </p><p>Releasing may be performed before exit via the <code><a href="Control-Monad-Trans-Resource.html#v:release">release</a></code> function. This is a highly recommended optimization, as it will ensure that scarce resources are freed early. Note that calling <code>release</code> will deregister the action, so that a release action will only ever be called once. </p></div><div class="subs instances"><p id="control.i:ResourceT" class="caption collapser" onclick="toggleSection('i:ResourceT')">Instances</p><div id="section.i:ResourceT" class="show"><table><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Class.html#t:MonadTrans">MonadTrans</a> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/transformers-base-0.4.1/Control-Monad-Base.html#t:MonadBase">MonadBase</a> b m => <a href="/usr/share/doc/ghc/html/libraries/transformers-base-0.4.1/Control-Monad-Base.html#t:MonadBase">MonadBase</a> b (<a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> b m => <a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> b (<a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> (<a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Functor">Functor</a> (<a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Typeable.html#t:Typeable1">Typeable1</a> m => <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Typeable.html#t:Typeable1">Typeable1</a> (<a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Applicative.html#t:Applicative">Applicative</a> (<a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> m => <a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> (<a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:ReleaseKey" class="def">ReleaseKey</a> <a href="src/Control-Monad-Trans-Resource.html#ReleaseKey" class="link">Source</a></p><div class="doc"><p>A lookup key for a specific release action. This value is returned by <code><a href="Control-Monad-Trans-Resource.html#v:register">register</a></code>, <code><a href="Control-Monad-Trans-Resource.html#v:with">with</a></code> and <code><a href="Control-Monad-Trans-Resource.html#v:withIO">withIO</a></code>, and is passed to <code><a href="Control-Monad-Trans-Resource.html#v:release">release</a></code>. </p></div><div class="subs instances"><p id="control.i:ReleaseKey" class="caption collapser" onclick="toggleSection('i:ReleaseKey')">Instances</p><div id="section.i:ReleaseKey" class="show"><table><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Typeable.html#t:Typeable">Typeable</a> <a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a></td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:2">Unwrap </h1><div class="top"><p class="src"><a name="v:runResourceT" class="def">runResourceT</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m a -> m a<a href="src/Control-Monad-Trans-Resource.html#runResourceT" class="link">Source</a></p><div class="doc"><p>Unwrap a <code><a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a></code> transformer, and call all registered release actions. </p><p>Note that there is some reference counting involved due to <code><a href="Control-Monad-Trans-Resource.html#v:resourceForkIO">resourceForkIO</a></code>. If multiple threads are sharing the same collection of resources, only the last call to <code>runResourceT</code> will deallocate the resources. </p></div></div><h1 id="g:3">Resource allocation </h1><div class="top"><p class="src"><a name="v:with" class="def">with</a><a href="src/Control-Monad-Trans-Resource.html#with" class="link">Source</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m</td><td class="doc empty"> </td></tr><tr><td class="src">=> <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m a</td><td class="doc"><p>allocate </p></td></tr><tr><td class="src">-> (a -> <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>)</td><td class="doc"><p>free resource </p></td></tr><tr><td class="src">-> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m (<a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a>, a)</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Perform some allocation, and automatically register a cleanup action. </p><p>If you are performing an <code>IO</code> action, it will likely be easier to use the <code><a href="Control-Monad-Trans-Resource.html#v:withIO">withIO</a></code> function, which handles types more cleanly. </p></div></div><div class="top"><p class="src"><a name="v:withIO" class="def">withIO</a><a href="src/Control-Monad-Trans-Resource.html#withIO" class="link">Source</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Monad-Trans-Resource.html#t:ResourceIO">ResourceIO</a> m</td><td class="doc empty"> </td></tr><tr><td class="src">=> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a</td><td class="doc"><p>allocate </p></td></tr><tr><td class="src">-> (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>)</td><td class="doc"><p>free resource </p></td></tr><tr><td class="src">-> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m (<a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a>, a)</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Same as <code><a href="Control-Monad-Trans-Resource.html#v:with">with</a></code>, but explicitly uses <code>IO</code> as a base. </p></div></div><div class="top"><p class="src"><a name="v:register" class="def">register</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a><a href="src/Control-Monad-Trans-Resource.html#register" class="link">Source</a></p><div class="doc"><p>Register some action that will be called precisely once, either when <code><a href="Control-Monad-Trans-Resource.html#v:runResourceT">runResourceT</a></code> is called, or when the <code><a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a></code> is passed to <code><a href="Control-Monad-Trans-Resource.html#v:release">release</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:release" class="def">release</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:ReleaseKey">ReleaseKey</a> -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a><a href="src/Control-Monad-Trans-Resource.html#release" class="link">Source</a></p><div class="doc"><p>Call a release action early, and deregister it from the list of cleanup actions to be performed. </p></div></div><h1 id="g:4">Use references </h1><div class="top"><p class="src"><a name="v:readRef" class="def">readRef</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m) a -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m a<a href="src/Control-Monad-Trans-Resource.html#readRef" class="link">Source</a></p><div class="doc"><p>Read a value from a reference. </p></div></div><div class="top"><p class="src"><a name="v:writeRef" class="def">writeRef</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m) a -> a -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a><a href="src/Control-Monad-Trans-Resource.html#writeRef" class="link">Source</a></p><div class="doc"><p>Write a value to a reference. </p></div></div><div class="top"><p class="src"><a name="v:newRef" class="def">newRef</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => a -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m (<a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m) a)<a href="src/Control-Monad-Trans-Resource.html#newRef" class="link">Source</a></p><div class="doc"><p>Create a new reference. </p></div></div><h1 id="g:5">Special actions </h1><div class="top"><p class="src"><a name="v:resourceForkIO" class="def">resourceForkIO</a> :: <a href="Control-Monad-Trans-Resource.html#t:ResourceIO">ResourceIO</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Concurrent.html#t:ThreadId">ThreadId</a><a href="src/Control-Monad-Trans-Resource.html#resourceForkIO" class="link">Source</a></p><div class="doc"><p>Introduce a reference-counting scheme to allow a resource context to be shared by multiple threads. Once the last thread exits, all remaining resources will be released. </p><p>Note that abuse of this function will greatly delay the deallocation of registered resources. This function should be used with care. A general guideline: </p><p>If you are allocating a resource that should be shared by multiple threads, and will be held for a long time, you should allocate it at the beginning of a new <code>ResourceT</code> block and then call <code>resourceForkIO</code> from there. </p></div></div><h1 id="g:6">Monad transformation </h1><div class="top"><p class="src"><a name="v:transResourceT" class="def">transResourceT</a> :: <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m ~ <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> n => (m a -> n b) -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m a -> <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> n b<a href="src/Control-Monad-Trans-Resource.html#transResourceT" class="link">Source</a></p><div class="doc"><p>Transform the monad a <code>ResourceT</code> lives in. This is most often used to strip or add new transformers to a stack, e.g. to run a <code>ReaderT</code>. Note that the original and new monad must both have the same <code><a href="Control-Monad-Trans-Resource.html#t:Base">Base</a></code> monad. </p></div></div><h1 id="g:7">A specific Exception transformer </h1><div class="top"><p class="src"><span class="keyword">newtype</span> <a name="t:ExceptionT" class="def">ExceptionT</a> m a <a href="src/Control-Monad-Trans-Resource.html#ExceptionT" class="link">Source</a></p><div class="doc"><p>The express purpose of this transformer is to allow the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST.html#t:ST">ST</a></code> monad to catch exceptions via the <code><a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a></code> typeclass. </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:ExceptionT" class="def">ExceptionT</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><dl><dt class="src"><a name="v:runExceptionT" class="def">runExceptionT</a> :: m (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Either.html#t:Either">Either</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a> a)</dt><dd class="doc empty"> </dd></dl><div class="clear"></div></div></td></tr></table></div><div class="subs instances"><p id="control.i:ExceptionT" class="caption collapser" onclick="toggleSection('i:ExceptionT')">Instances</p><div id="section.i:ExceptionT" class="show"><table><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Class.html#t:MonadTrans">MonadTrans</a> <a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadTransControl">MonadTransControl</a> <a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/transformers-base-0.4.1/Control-Monad-Base.html#t:MonadBase">MonadBase</a> b m => <a href="/usr/share/doc/ghc/html/libraries/transformers-base-0.4.1/Control-Monad-Base.html#t:MonadBase">MonadBase</a> b (<a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> b m => <a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> b (<a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> (<a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Functor">Functor</a> (<a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Applicative.html#t:Applicative">Applicative</a> (<a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m, <a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m) m) => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:runExceptionT_" class="def">runExceptionT_</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m a -> m a<a href="src/Control-Monad-Trans-Resource.html#runExceptionT_" class="link">Source</a></p><div class="doc"><p>Same as <code><a href="Control-Monad-Trans-Resource.html#v:runExceptionT">runExceptionT</a></code>, but immediately <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Exception-Base.html#v:throw">throw</a></code> any exception returned. </p></div></div><h1 id="g:8">Type class/associated types </h1><div class="top"><p class="src"><span class="keyword">class</span> (<a href="Control-Monad-Trans-Resource.html#t:HasRef">HasRef</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m), <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m) => <a name="t:Resource" class="def">Resource</a> m <span class="keyword">where</span><a href="src/Control-Monad-Trans-Resource.html#Resource" class="link">Source</a></p><div class="doc"><p>A <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a></code> with a base that has mutable references, and allows some way to run base actions and clean up properly. </p></div><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a name="t:Base" class="def">Base</a> m :: * -> *<a href="src/Control-Monad-Trans-Resource.html#Base" class="link">Source</a></p><div class="doc"><p>The base monad for the current monad stack. This will usually be <code>IO</code> or <code>ST</code>. </p></div></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:resourceLiftBase" class="def">resourceLiftBase</a> :: <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m a -> m a<a href="src/Control-Monad-Trans-Resource.html#resourceLiftBase" class="link">Source</a></p><div class="doc"><p>Run some action in the <code>Base</code> monad. This function corresponds to <code><a href="/usr/share/doc/ghc/html/libraries/transformers-base-0.4.1/Control-Monad-Base.html#v:liftBase">liftBase</a></code>, but due to various type issues, we need to have our own version here. </p></div><p class="src"><a name="v:resourceBracket_" class="def">resourceBracket_</a><a href="src/Control-Monad-Trans-Resource.html#resourceBracket_" class="link">Source</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></td><td class="doc"><p>init </p></td></tr><tr><td class="src">-> <a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></td><td class="doc"><p>cleanup </p></td></tr><tr><td class="src">-> m c</td><td class="doc"><p>body </p></td></tr><tr><td class="src">-> m c</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Guarantee that some initialization and cleanup code is called before and after some action. Note that the initialization and cleanup lives in the base monad, while the body is in the top monad. </p></div></div><div class="subs instances"><p id="control.i:Resource" class="caption collapser" onclick="toggleSection('i:Resource')">Instances</p><div id="section.i:Resource" class="show"><table><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadTransControl">MonadTransControl</a> t, <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m, <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> (t m)) => <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> (t m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST.html#t:ST">ST</a> s)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST-Lazy.html#t:ST">ST</a> s)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">class</span> <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a name="t:ResourceUnsafeIO" class="def">ResourceUnsafeIO</a> m <span class="keyword">where</span><a href="src/Control-Monad-Trans-Resource.html#ResourceUnsafeIO" class="link">Source</a></p><div class="doc"><p>A <code><a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a></code> based on some monad which allows running of some <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></code> actions, via unsafe calls. This applies to <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></code> and <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST.html#t:ST">ST</a></code>, for instance. </p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:unsafeFromIO" class="def">unsafeFromIO</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a -> m a<a href="src/Control-Monad-Trans-Resource.html#unsafeFromIO" class="link">Source</a></p></div><div class="subs instances"><p id="control.i:ResourceUnsafeIO" class="caption collapser" onclick="toggleSection('i:ResourceUnsafeIO')">Instances</p><div id="section.i:ResourceUnsafeIO" class="show"><table><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceUnsafeIO">ResourceUnsafeIO</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadTransControl">MonadTransControl</a> t, <a href="Control-Monad-Trans-Resource.html#t:ResourceUnsafeIO">ResourceUnsafeIO</a> m, <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> (t m)) => <a href="Control-Monad-Trans-Resource.html#t:ResourceUnsafeIO">ResourceUnsafeIO</a> (t m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceUnsafeIO">ResourceUnsafeIO</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST.html#t:ST">ST</a> s)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceUnsafeIO">ResourceUnsafeIO</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST-Lazy.html#t:ST">ST</a> s)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">class</span> (<a href="Control-Monad-Trans-Resource.html#t:ResourceBaseIO">ResourceBaseIO</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m), <a href="Control-Monad-Trans-Resource.html#t:ResourceUnsafeIO">ResourceUnsafeIO</a> m, <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m, <a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> m, <a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> m) => <a name="t:ResourceIO" class="def">ResourceIO</a> m <a href="src/Control-Monad-Trans-Resource.html#ResourceIO" class="link">Source</a></p><div class="doc"><p>A <code><a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a></code> which can safely run <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></code> calls. </p></div><div class="subs instances"><p id="control.i:ResourceIO" class="caption collapser" onclick="toggleSection('i:ResourceIO')">Instances</p><div id="section.i:ResourceIO" class="show"><table><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceIO">ResourceIO</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadTransControl">MonadTransControl</a> t, <a href="Control-Monad-Trans-Resource.html#t:ResourceIO">ResourceIO</a> m, <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> (t m), <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (t m), <a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> (t m), <a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> (t m)) => <a href="Control-Monad-Trans-Resource.html#t:ResourceIO">ResourceIO</a> (t m)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">class</span> <a name="t:ResourceBaseIO" class="def">ResourceBaseIO</a> m <span class="keyword">where</span><a href="src/Control-Monad-Trans-Resource.html#ResourceBaseIO" class="link">Source</a></p><div class="doc"><p>A helper class for <code><a href="Control-Monad-Trans-Resource.html#t:ResourceIO">ResourceIO</a></code>, stating that the base monad provides <code>IO</code> actions. </p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:safeFromIOBase" class="def">safeFromIOBase</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a -> m a<a href="src/Control-Monad-Trans-Resource.html#safeFromIOBase" class="link">Source</a></p></div><div class="subs instances"><p id="control.i:ResourceBaseIO" class="caption collapser" onclick="toggleSection('i:ResourceBaseIO')">Instances</p><div id="section.i:ResourceBaseIO" class="show"><table><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceBaseIO">ResourceBaseIO</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">class</span> <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a name="t:ResourceThrow" class="def">ResourceThrow</a> m <span class="keyword">where</span><a href="src/Control-Monad-Trans-Resource.html#ResourceThrow" class="link">Source</a></p><div class="doc"><p>A <code><a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a></code> which can throw exceptions. Note that this does not work in a vanilla <code>ST</code> monad. Instead, you should use the <code><a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a></code> transformer on top of <code>ST</code>. </p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:resourceThrow" class="def">resourceThrow</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Exception-Base.html#t:Exception">Exception</a> e => e -> m a<a href="src/Control-Monad-Trans-Resource.html#resourceThrow" class="link">Source</a></p></div><div class="subs instances"><p id="control.i:ResourceThrow" class="caption collapser" onclick="toggleSection('i:ResourceThrow')">Instances</p><div id="section.i:ResourceThrow" class="show"><table><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Maybe.html#t:MaybeT">MaybeT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-List.html#t:ListT">ListT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Identity.html#t:IdentityT">IdentityT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m, <a href="/usr/share/doc/ghc/html/libraries/monad-control-0.3.1/Control-Monad-Trans-Control.html#t:MonadBaseControl">MonadBaseControl</a> (<a href="Control-Monad-Trans-Resource.html#t:Base">Base</a> m) m) => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="Control-Monad-Trans-Resource.html#t:ExceptionT">ExceptionT</a> m)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Monoid.html#t:Monoid">Monoid</a> w, <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m) => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Writer-Strict.html#t:WriterT">WriterT</a> w m)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Monoid.html#t:Monoid">Monoid</a> w, <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m) => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Writer-Lazy.html#t:WriterT">WriterT</a> w m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-State-Strict.html#t:StateT">StateT</a> s m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-State-Lazy.html#t:StateT">StateT</a> s m)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Reader.html#t:ReaderT">ReaderT</a> r m)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Error.html#t:Error">Error</a> e, <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m) => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Error.html#t:ErrorT">ErrorT</a> e m)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Monoid.html#t:Monoid">Monoid</a> w, <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m) => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-RWS-Strict.html#t:RWST">RWST</a> r w s m)</td><td class="doc empty"> </td></tr><tr><td class="src">(<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Monoid.html#t:Monoid">Monoid</a> w, <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> m) => <a href="Control-Monad-Trans-Resource.html#t:ResourceThrow">ResourceThrow</a> (<a href="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-RWS-Lazy.html#t:RWST">RWST</a> r w s m)</td><td class="doc empty"> </td></tr></table></div></div></div><h2 id="g:9">Low-level </h2><div class="top"><p class="src"><span class="keyword">class</span> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad.html#t:Monad">Monad</a> m => <a name="t:HasRef" class="def">HasRef</a> m <span class="keyword">where</span><a href="src/Control-Monad-Trans-Resource.html#HasRef" class="link">Source</a></p><div class="doc"><p>A base monad which provides mutable references and some exception-safe way of interacting with them. For monads which cannot handle exceptions (e.g., <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST.html#t:ST">ST</a></code>), exceptions may be ignored. However, in such cases, scarce resources should <em>not</em> be allocated in those monads, as exceptions may cause the cleanup functions to not run. </p><p>The instance for <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></code>, however, is fully exception-safe. </p><p>Minimal complete definition: <code>Ref</code>, <code>newRef'</code>, <code>readRef'</code> and <code>writeRef'</code>. </p></div><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a name="t:Ref" class="def">Ref</a> m :: * -> *<a href="src/Control-Monad-Trans-Resource.html#Ref" class="link">Source</a></p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:newRef-39-" class="def">newRef'</a> :: a -> m (<a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> m a)<a href="src/Control-Monad-Trans-Resource.html#newRef%27" class="link">Source</a></p><p class="src"><a name="v:readRef-39-" class="def">readRef'</a> :: <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> m a -> m a<a href="src/Control-Monad-Trans-Resource.html#readRef%27" class="link">Source</a></p><p class="src"><a name="v:writeRef-39-" class="def">writeRef'</a> :: <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> m a -> a -> m <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a><a href="src/Control-Monad-Trans-Resource.html#writeRef%27" class="link">Source</a></p><p class="src"><a name="v:atomicModifyRef-39-" class="def">atomicModifyRef'</a> :: <a href="Control-Monad-Trans-Resource.html#t:Ref">Ref</a> m a -> (a -> (a, b)) -> m b<a href="src/Control-Monad-Trans-Resource.html#atomicModifyRef%27" class="link">Source</a></p><div class="doc"><p>For monads supporting multi-threaded access (e.g., <code>IO</code>), this much be an atomic modification. </p></div><p class="src"><a name="v:mask" class="def">mask</a> :: ((<span class="keyword">forall</span> a. m a -> m a) -> m b) -> m b<a href="src/Control-Monad-Trans-Resource.html#mask" class="link">Source</a></p><p class="src"><a name="v:mask_" class="def">mask_</a> :: m a -> m a<a href="src/Control-Monad-Trans-Resource.html#mask_" class="link">Source</a></p><p class="src"><a name="v:try" class="def">try</a> :: m a -> m (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Either.html#t:Either">Either</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a> a)<a href="src/Control-Monad-Trans-Resource.html#try" class="link">Source</a></p></div><div class="subs instances"><p id="control.i:HasRef" class="caption collapser" onclick="toggleSection('i:HasRef')">Instances</p><div id="section.i:HasRef" class="show"><table><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:HasRef">HasRef</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:HasRef">HasRef</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST.html#t:ST">ST</a> s)</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad-Trans-Resource.html#t:HasRef">HasRef</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Monad-ST-Lazy.html#t:ST">ST</a> s)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:InvalidAccess" class="def">InvalidAccess</a> <a href="src/Control-Monad-Trans-Resource.html#InvalidAccess" class="link">Source</a></p><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:InvalidAccess" class="def">InvalidAccess</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><dl><dt class="src"><a name="v:functionName" class="def">functionName</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Char.html#t:String">String</a></dt><dd class="doc empty"> </dd></dl><div class="clear"></div></div></td></tr></table></div><div class="subs instances"><p id="control.i:InvalidAccess" class="caption collapser" onclick="toggleSection('i:InvalidAccess')">Instances</p><div id="section.i:InvalidAccess" class="show"><table><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Text-Show.html#t:Show">Show</a> <a href="Control-Monad-Trans-Resource.html#t:InvalidAccess">InvalidAccess</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Typeable.html#t:Typeable">Typeable</a> <a href="Control-Monad-Trans-Resource.html#t:InvalidAccess">InvalidAccess</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Monad-Trans-Resource.html#t:InvalidAccess">InvalidAccess</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:resourceActive" class="def">resourceActive</a> :: <a href="Control-Monad-Trans-Resource.html#t:Resource">Resource</a> m => <a href="Control-Monad-Trans-Resource.html#t:ResourceT">ResourceT</a> m <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a><a href="src/Control-Monad-Trans-Resource.html#resourceActive" class="link">Source</a></p><div class="doc"><p>Determine if the current <code>ResourceT</code> is still active. This is necessary for such cases as lazy I/O, where an unevaluated thunk may still refer to a closed <code>ResourceT</code>. </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.9.2</p></div></body></html>