-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Deterministic allocation and freeing of scarce resources.
--   
--   Hackage documentation generation is not reliable. For up to date
--   documentation, please see:
--   http://www.stackage.org/package/resourcet.
@package resourcet
@version 1.3.0

module Data.Acquire.Internal

-- | A method for acquiring a scarce resource, providing the means of
--   freeing it when no longer needed. This data type provides
--   Functor/Applicative/Monad instances for
--   composing different resources together. You can allocate these
--   resources using either the bracket pattern (via
--   with) or using ResourceT (via
--   allocateAcquire).
--   
--   This concept was originally introduced by Gabriel Gonzalez and
--   described at:
--   http://www.haskellforall.com/2013/06/the-resource-applicative.html.
--   The implementation in this package is slightly different, due to
--   taking a different approach to async exception safety.
newtype Acquire a
Acquire :: ((forall b. () => IO b -> IO b) -> IO (Allocated a)) -> Acquire a
data Allocated a
Allocated :: !a -> !ReleaseType -> IO () -> Allocated a

-- | Allocate the given resource and provide it to the provided function.
--   The resource will be freed as soon as the inner block is exited,
--   whether normally or via an exception. This function is similar in
--   function to bracket.
with :: MonadUnliftIO m => Acquire a -> (a -> m b) -> m b

-- | Create an Acquire value using the given allocate and free
--   functions.
--   
--   To acquire and free the resource in an arbitrary monad with
--   MonadUnliftIO, do the following:
--   
--   
--   acquire <- withRunInIO $ \runInIO ->
--     return $ mkAcquire (runInIO create) (runInIO . free)
--   
--   
--   Note that this is only safe if the Acquire is run and freed within the
--   same monadic scope it was created in.
mkAcquire :: IO a -> (a -> IO ()) -> Acquire a

-- | The way in which a release is called.
data ReleaseType
ReleaseEarly :: ReleaseType
ReleaseNormal :: ReleaseType
ReleaseExceptionWith :: SomeException -> ReleaseType

-- | Deprecated: Use ReleaseExceptionWith, which has the
--   exception in the constructor. This pattern synonym hides the exception
--   and can obscure problems.
pattern ReleaseException :: ReleaseType

-- | Same as mkAcquire, but the cleanup function will be informed of
--   how cleanup was initiated. This allows you to distinguish, for
--   example, between normal and exceptional exits.
--   
--   To acquire and free the resource in an arbitrary monad with
--   MonadUnliftIO, do the following:
--   
--   
--   acquire <- withRunInIO $ \runInIO ->
--     return $ mkAcquireType (runInIO create) (\a -> runInIO . free a)
--   
--   
--   Note that this is only safe if the Acquire is run and freed within the
--   same monadic scope it was created in.
mkAcquireType :: IO a -> (a -> ReleaseType -> IO ()) -> Acquire a
instance GHC.Internal.Base.Applicative Data.Acquire.Internal.Acquire
instance GHC.Internal.Base.Functor Data.Acquire.Internal.Acquire
instance GHC.Internal.Base.Monad Data.Acquire.Internal.Acquire
instance Control.Monad.IO.Class.MonadIO Data.Acquire.Internal.Acquire
instance GHC.Internal.Show.Show Data.Acquire.Internal.ReleaseType

module Control.Monad.Trans.Resource.Internal

-- | Indicates either an error in the library, or misuse of it (e.g., a
--   ResourceT's state is accessed after being released).
--   
--   Since 0.3.0
data InvalidAccess
InvalidAccess :: String -> InvalidAccess
[functionName] :: InvalidAccess -> String

-- | A Monad which allows for safe resource allocation. In theory,
--   any monad transformer stack which includes a ResourceT can be
--   an instance of MonadResource.
--   
--   Note: runResourceT has a requirement for a MonadUnliftIO
--   m monad, which allows control operations to be lifted. A
--   MonadResource does not have this requirement. This means that
--   transformers such as ContT can be an instance of
--   MonadResource. However, the ContT wrapper will need
--   to be unwrapped before calling runResourceT.
--   
--   Since 0.3.0
class MonadIO m => MonadResource (m :: Type -> Type)

-- | Lift a ResourceT IO action into the current Monad.
--   
--   Since 0.4.0
liftResourceT :: MonadResource m => ResourceT IO a -> m a

-- | A lookup key for a specific release action. This value is returned by
--   register and allocate, and is passed to
--   release.
--   
--   Since 0.3.0
data ReleaseKey
ReleaseKey :: !IORef ReleaseMap -> !Int -> ReleaseKey
data ReleaseMap
ReleaseMap :: !NextKey -> !RefCount -> !IntMap (ReleaseType -> IO ()) -> ReleaseMap
ReleaseMapClosed :: ReleaseMap

-- | Convenient alias for ResourceT IO.
type ResIO = ResourceT IO

-- | 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
--   allocate. allocate 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.
--   
--   Since 0.3.0
newtype ResourceT (m :: Type -> Type) a
ResourceT :: (IORef ReleaseMap -> m a) -> ResourceT (m :: Type -> Type) a
[unResourceT] :: ResourceT (m :: Type -> Type) a -> IORef ReleaseMap -> m a
stateAlloc :: IORef ReleaseMap -> IO ()
stateCleanup :: ReleaseType -> IORef ReleaseMap -> IO ()

-- | 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.
--   
--   Note that this function is a slight generalization of hoist.
--   
--   Since 0.3.0
transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b
register' :: IORef ReleaseMap -> IO () -> IO ReleaseKey

-- | Since 1.1.2
registerType :: IORef ReleaseMap -> (ReleaseType -> IO ()) -> IO ReleaseKey

-- | Thrown when one or more cleanup functions themselves throw an
--   exception during cleanup.
data ResourceCleanupException
ResourceCleanupException :: !Maybe SomeException -> !SomeException -> ![SomeException] -> ResourceCleanupException

-- | If the ResourceT block exited due to an exception, this is that
--   exception.
[rceOriginalException] :: ResourceCleanupException -> !Maybe SomeException

-- | The first cleanup exception. We keep this separate from
--   rceOtherCleanupExceptions to prove that there's at least one
--   (i.e., a non-empty list).
[rceFirstCleanupException] :: ResourceCleanupException -> !SomeException

-- | All other exceptions in cleanups.
[rceOtherCleanupExceptions] :: ResourceCleanupException -> ![SomeException]

-- | Clean up a release map, but throw a ResourceCleanupException if
--   anything goes wrong in the cleanup handlers.
stateCleanupChecked :: Maybe SomeException -> IORef ReleaseMap -> IO ()
instance GHC.Internal.Base.Alternative m => GHC.Internal.Base.Alternative (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance GHC.Internal.Base.Applicative m => GHC.Internal.Base.Applicative (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance GHC.Internal.Exception.Type.Exception Control.Monad.Trans.Resource.Internal.InvalidAccess
instance GHC.Internal.Exception.Type.Exception Control.Monad.Trans.Resource.Internal.ResourceCleanupException
instance GHC.Internal.Base.Functor m => GHC.Internal.Base.Functor (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance GHC.Internal.Control.Monad.Fail.MonadFail m => GHC.Internal.Control.Monad.Fail.MonadFail (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance GHC.Internal.Control.Monad.Fix.MonadFix m => GHC.Internal.Control.Monad.Fix.MonadFix (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance GHC.Internal.Base.MonadPlus m => GHC.Internal.Base.MonadPlus (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.RWS.Class.MonadRWS r w s m => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance GHC.Internal.Base.Monad m => GHC.Internal.Base.Monad (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Cont.ContT r m)
instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Except.ExceptT e m)
instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Identity.IdentityT m)
instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Maybe.MaybeT m)
instance (GHC.Internal.Base.Monoid w, Control.Monad.Trans.Resource.Internal.MonadResource m) => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance (GHC.Internal.Base.Monoid w, Control.Monad.Trans.Resource.Internal.MonadResource m) => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Reader.ReaderT r m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.State.Strict.StateT s m)
instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.State.Lazy.StateT s m)
instance (GHC.Internal.Base.Monoid w, Control.Monad.Trans.Resource.Internal.MonadResource m) => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Writer.Strict.WriterT w m)
instance (GHC.Internal.Base.Monoid w, Control.Monad.Trans.Resource.Internal.MonadResource m) => Control.Monad.Trans.Resource.Internal.MonadResource (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Trans.Class.MonadTrans Control.Monad.Trans.Resource.Internal.ResourceT
instance Control.Monad.IO.Unlift.MonadUnliftIO m => Control.Monad.IO.Unlift.MonadUnliftIO (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance Control.Monad.Primitive.PrimMonad m => Control.Monad.Primitive.PrimMonad (Control.Monad.Trans.Resource.Internal.ResourceT m)
instance GHC.Internal.Show.Show Control.Monad.Trans.Resource.Internal.InvalidAccess
instance GHC.Internal.Show.Show Control.Monad.Trans.Resource.Internal.ResourceCleanupException

-- | This was previously known as the Resource monad. However, that term is
--   confusing next to the ResourceT transformer, so it has been renamed.
module Data.Acquire

-- | A method for acquiring a scarce resource, providing the means of
--   freeing it when no longer needed. This data type provides
--   Functor/Applicative/Monad instances for
--   composing different resources together. You can allocate these
--   resources using either the bracket pattern (via
--   with) or using ResourceT (via
--   allocateAcquire).
--   
--   This concept was originally introduced by Gabriel Gonzalez and
--   described at:
--   http://www.haskellforall.com/2013/06/the-resource-applicative.html.
--   The implementation in this package is slightly different, due to
--   taking a different approach to async exception safety.
data Acquire a

-- | Allocate the given resource and provide it to the provided function.
--   The resource will be freed as soon as the inner block is exited,
--   whether normally or via an exception. This function is similar in
--   function to bracket.
with :: MonadUnliftIO m => Acquire a -> (a -> m b) -> m b

-- | Longer name for with, in case with is not obvious
--   enough in context.
withAcquire :: MonadUnliftIO m => Acquire a -> (a -> m b) -> m b

-- | Create an Acquire value using the given allocate and free
--   functions.
--   
--   To acquire and free the resource in an arbitrary monad with
--   MonadUnliftIO, do the following:
--   
--   
--   acquire <- withRunInIO $ \runInIO ->
--     return $ mkAcquire (runInIO create) (runInIO . free)
--   
--   
--   Note that this is only safe if the Acquire is run and freed within the
--   same monadic scope it was created in.
mkAcquire :: IO a -> (a -> IO ()) -> Acquire a

-- | Same as mkAcquire, but the cleanup function will be informed of
--   how cleanup was initiated. This allows you to distinguish, for
--   example, between normal and exceptional exits.
--   
--   To acquire and free the resource in an arbitrary monad with
--   MonadUnliftIO, do the following:
--   
--   
--   acquire <- withRunInIO $ \runInIO ->
--     return $ mkAcquireType (runInIO create) (\a -> runInIO . free a)
--   
--   
--   Note that this is only safe if the Acquire is run and freed within the
--   same monadic scope it was created in.
mkAcquireType :: IO a -> (a -> ReleaseType -> IO ()) -> Acquire a

-- | Allocate a resource and register an action with the
--   MonadResource to free the resource.
allocateAcquire :: MonadResource m => Acquire a -> m (ReleaseKey, a)

-- | The way in which a release is called.
data ReleaseType
ReleaseEarly :: ReleaseType
ReleaseNormal :: ReleaseType
ReleaseExceptionWith :: SomeException -> ReleaseType

-- | Deprecated: Use ReleaseExceptionWith, which has the
--   exception in the constructor. This pattern synonym hides the exception
--   and can obscure problems.
pattern ReleaseException :: ReleaseType

-- | Allocate resources which are guaranteed to be released.
--   
--   For more information, see
--   https://github.com/snoyberg/conduit/tree/master/resourcet#readme.
--   
--   One point to note: all register cleanup actions live in the
--   IO monad, not the main monad. This allows both more efficient
--   code, and for monads to be transformed.
module Control.Monad.Trans.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
--   allocate. allocate 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.
--   
--   Since 0.3.0
data ResourceT (m :: Type -> Type) a

-- | Convenient alias for ResourceT IO.
type ResIO = ResourceT IO

-- | A lookup key for a specific release action. This value is returned by
--   register and allocate, and is passed to
--   release.
--   
--   Since 0.3.0
data ReleaseKey

-- | Unwrap a ResourceT transformer, and call all registered release
--   actions.
--   
--   Note that there is some reference counting involved due to
--   resourceForkIO. If multiple threads are sharing the same
--   collection of resources, only the last call to runResourceT
--   will deallocate the resources.
--   
--   NOTE Since version 1.2.0, this function will throw a
--   ResourceCleanupException if any of the cleanup functions throw
--   an exception.
runResourceT :: MonadUnliftIO m => ResourceT m a -> m a

-- | Backwards compatible alias for runResourceT.
runResourceTChecked :: MonadUnliftIO m => ResourceT m a -> m a

-- | Thrown when one or more cleanup functions themselves throw an
--   exception during cleanup.
data ResourceCleanupException
ResourceCleanupException :: !Maybe SomeException -> !SomeException -> ![SomeException] -> ResourceCleanupException

-- | If the ResourceT block exited due to an exception, this is that
--   exception.
[rceOriginalException] :: ResourceCleanupException -> !Maybe SomeException

-- | The first cleanup exception. We keep this separate from
--   rceOtherCleanupExceptions to prove that there's at least one
--   (i.e., a non-empty list).
[rceFirstCleanupException] :: ResourceCleanupException -> !SomeException

-- | All other exceptions in cleanups.
[rceOtherCleanupExceptions] :: ResourceCleanupException -> ![SomeException]

-- | 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.
--   
--   The first parameter is a function which will be used to create the
--   thread, such as forkIO or async.
--   
--   Note that abuse of this function will greatly delay the deallocation
--   of registered resources. This function should be used with care. A
--   general guideline:
--   
--   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 ResourceT block and then call
--   resourceForkWith from there.
resourceForkWith :: forall (m :: Type -> Type) a. MonadUnliftIO m => (IO () -> IO a) -> ResourceT m () -> ResourceT m a

-- | Launch a new reference counted resource context using forkIO.
--   
--   This is defined as resourceForkWith forkIO.
--   
--   Note: Using regular forkIO inside of a ResourceT is
--   inherently unsafe, since the forked thread may try access the
--   resources of the parent after they are cleaned up. When you use
--   resourceForkIO or resourceForkWith, ResourceT is
--   made aware of the new thread, and will only cleanup resources when all
--   threads finish. Other concurrency mechanisms, like
--   concurrently or race, are safe to use.
--   
--   If you encounter InvalidAccess exceptions ("The mutable state
--   is being accessed after cleanup"), use of forkIO is a possible
--   culprit.
resourceForkIO :: forall (m :: Type -> Type). MonadUnliftIO m => ResourceT m () -> ResourceT m ThreadId

-- | 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.
--   
--   Note that this function is a slight generalization of hoist.
--   
--   Since 0.3.0
transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b

-- | This function mirrors join at the transformer level: it will
--   collapse two levels of ResourceT into a single
--   ResourceT.
--   
--   Since 0.4.6
joinResourceT :: forall (m :: Type -> Type) a. ResourceT (ResourceT m) a -> ResourceT m a

-- | Perform some allocation, and automatically register a cleanup action.
--   
--   This is almost identical to calling the allocation and then
--   registering the release action, but this properly handles
--   masking of asynchronous exceptions.
--   
--   Since 0.3.0
allocate :: MonadResource m => IO a -> (a -> IO ()) -> m (ReleaseKey, a)

-- | Perform some allocation where the return value is not required, and
--   automatically register a cleanup action.
--   
--   allocate_ is to allocate as bracket_ is to
--   bracket
--   
--   This is almost identical to calling the allocation and then
--   registering the release action, but this properly handles
--   masking of asynchronous exceptions.
allocate_ :: MonadResource m => IO a -> IO () -> m ReleaseKey

-- | Register some action that will be called precisely once, either when
--   runResourceT is called, or when the ReleaseKey is passed
--   to release.
--   
--   Since 0.3.0
register :: MonadResource m => IO () -> m ReleaseKey

-- | Call a release action early, and deregister it from the list of
--   cleanup actions to be performed.
--   
--   Since 0.3.0
release :: MonadIO m => ReleaseKey -> m ()

-- | Unprotect resource from cleanup actions; this allows you to send
--   resource into another resourcet process and reregister it there. It
--   returns a release action that should be run in order to clean resource
--   or Nothing in case if resource is already freed.
--   
--   Since 0.4.5
unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ()))

-- | Perform asynchronous exception masking.
--   
--   This is more general then Control.Exception.mask, yet more
--   efficient than Control.Exception.Lifted.mask.
--   
--   Since 0.3.0
resourceMask :: MonadResource m => ((forall a. () => ResourceT IO a -> ResourceT IO a) -> ResourceT IO b) -> m b

-- | A Monad which allows for safe resource allocation. In theory,
--   any monad transformer stack which includes a ResourceT can be
--   an instance of MonadResource.
--   
--   Note: runResourceT has a requirement for a MonadUnliftIO
--   m monad, which allows control operations to be lifted. A
--   MonadResource does not have this requirement. This means that
--   transformers such as ContT can be an instance of
--   MonadResource. However, the ContT wrapper will need
--   to be unwrapped before calling runResourceT.
--   
--   Since 0.3.0
class MonadIO m => MonadResource (m :: Type -> Type)

-- | Lift a ResourceT IO action into the current Monad.
--   
--   Since 0.4.0
liftResourceT :: MonadResource m => ResourceT IO a -> m a

-- | Just use MonadUnliftIO directly now, legacy explanation
--   continues:
--   
--   A Monad which can be used as a base for a ResourceT.
--   
--   A ResourceT has some restrictions on its base monad:
--   
--   
--   
- runResourceT requires an instance of
--   MonadUnliftIO.
--   
- MonadResource requires an instance of
--   MonadIO
--   
--   
--   Note that earlier versions of conduit had a typeclass
--   ResourceIO. This fulfills much the same role.
--   
--   Since 0.3.2

-- | Deprecated: Use MonadUnliftIO directly instead
type MonadResourceBase = MonadUnliftIO

-- | Indicates either an error in the library, or misuse of it (e.g., a
--   ResourceT's state is accessed after being released).
--   
--   Since 0.3.0
data InvalidAccess
InvalidAccess :: String -> InvalidAccess
[functionName] :: InvalidAccess -> String

-- | Monads which allow their actions to be run in IO.
--   
--   While MonadIO allows an IO action to be lifted into
--   another monad, this class captures the opposite concept: allowing you
--   to capture the monadic context. Note that, in order to meet the laws
--   given below, the intuition is that a monad must have no monadic state,
--   but may have monadic context. This essentially limits
--   MonadUnliftIO to ReaderT and IdentityT
--   transformers on top of IO.
--   
--   Laws. For any function run provided by withRunInIO, it
--   must meet the monad transformer laws as reformulated for
--   MonadUnliftIO:
--   
--   
--   
- 
run . return = return

--   
- 
run (m >>= f) = run m >>= run . f

--   
--   
--   Instances of MonadUnliftIO must also satisfy the following
--   laws:
--   
--   
--   
- Identity law withRunInIO (\run -> run m) =
--   m
--   
- Inverse law withRunInIO (\_ -> m) = liftIO
--   m
--   
--   
--   As an example of an invalid instance, a naive implementation of
--   MonadUnliftIO (StateT s m) might be
--   
--   
--   withRunInIO inner =
--     StateT $ \s ->
--       withRunInIO $ \run ->
--         inner (run . flip evalStateT s)
--   
--   
--   This breaks the identity law because the inner run m would
--   throw away any state changes in m.
class MonadIO m => MonadUnliftIO (m :: Type -> Type)

-- | The internal state held by a ResourceT transformer.
--   
--   Since 0.4.6
type InternalState = IORef ReleaseMap

-- | Get the internal state of the current ResourceT.
--   
--   Since 0.4.6
getInternalState :: forall (m :: Type -> Type). Monad m => ResourceT m InternalState

-- | Unwrap a ResourceT using the given InternalState.
--   
--   Since 0.4.6
runInternalState :: ResourceT m a -> InternalState -> m a

-- | Run an action in the underlying monad, providing it the
--   InternalState.
--   
--   Since 0.4.6
withInternalState :: (InternalState -> m a) -> ResourceT m a

-- | Create a new internal state. This state must be closed with
--   closeInternalState. It is your responsibility to ensure
--   exception safety. Caveat emptor!
--   
--   Since 0.4.9
createInternalState :: MonadIO m => m InternalState

-- | Close an internal state created by createInternalState.
--   
--   Since 0.4.9
closeInternalState :: MonadIO m => InternalState -> m ()

-- | A class for monads in which exceptions may be thrown.
--   
--   Instances should obey the following law:
--   
--   
--   throwM e >> x = throwM e
--   
--   
--   In other words, throwing an exception short-circuits the rest of the
--   monadic computation.
class Monad m => MonadThrow (m :: Type -> Type)

-- | Throw an exception. Note that this throws when this action is run in
--   the monad m, not when it is applied. It is a generalization
--   of Control.Exception's throwIO.
--   
--   Should satisfy the law:
--   
--   
--   throwM e >> f = throwM e
--   
throwM :: (MonadThrow m, HasCallStack, Exception e) => e -> m a

-- | Unlifted Control.Monad.Trans.Resource.
module UnliftIO.Resource

-- | Unlifted version of runResourceT.
runResourceT :: MonadUnliftIO m => ResourceT m a -> m a

-- | Lifted version of liftResourceT.
liftResourceT :: forall (m :: Type -> Type) a. MonadIO m => ResourceT IO a -> ResourceT m a

-- | Unlifted allocate.
allocateU :: (MonadUnliftIO m, MonadResource m) => m a -> (a -> m ()) -> m (ReleaseKey, a)

-- | Call a release action early, and deregister it from the list of
--   cleanup actions to be performed.
--   
--   Since 0.3.0
release :: MonadIO m => ReleaseKey -> m ()

-- | 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
--   allocate. allocate 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.
--   
--   Since 0.3.0
data ResourceT (m :: Type -> Type) a

-- | A lookup key for a specific release action. This value is returned by
--   register and allocate, and is passed to
--   release.
--   
--   Since 0.3.0
data ReleaseKey

-- | Perform some allocation, and automatically register a cleanup action.
--   
--   This is almost identical to calling the allocation and then
--   registering the release action, but this properly handles
--   masking of asynchronous exceptions.
--   
--   Since 0.3.0
allocate :: MonadResource m => IO a -> (a -> IO ()) -> 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.
--   
--   Since 0.3.0
register :: MonadResource m => IO () -> m ReleaseKey

-- | Unprotect resource from cleanup actions; this allows you to send
--   resource into another resourcet process and reregister it there. It
--   returns a release action that should be run in order to clean resource
--   or Nothing in case if resource is already freed.
--   
--   Since 0.4.5
unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ()))

-- | A Monad which allows for safe resource allocation. In theory,
--   any monad transformer stack which includes a ResourceT can be
--   an instance of MonadResource.
--   
--   Note: runResourceT has a requirement for a MonadUnliftIO
--   m monad, which allows control operations to be lifted. A
--   MonadResource does not have this requirement. This means that
--   transformers such as ContT can be an instance of
--   MonadResource. However, the ContT wrapper will need
--   to be unwrapped before calling runResourceT.
--   
--   Since 0.3.0
class MonadIO m => MonadResource (m :: Type -> Type)
