    {-# LANGUAGE RankNTypes, TypeFamilies, FlexibleContexts, FlexibleInstances,
          MultiParamTypeClasses, UndecidableInstances, ScopedTypeVariables,
          GeneralizedNewtypeDeriving, Trustworthy #-}
    {-# OPTIONS_GHC -fno-warn-orphans #-}

    {-| This module provides an orphan 'MonadMask' instance for 'Proxy' of the
        form:

    > instance (MonadMask m, MonadIO m) => MonadMask (Proxy a' a b' b m) where

        Which is needed to implement the instance for MonadSafe for Proxy.

        This module also provides generalized versions of some 'MonadCatch'
        operations so that you can also protect against premature termination of
        connected components.  For example, if you protect a 'readFile' computation
        using 'bracket' from this module:

    > -- readFile.hs
    > import Pipes
    > import qualified Pipes.Prelude as P
    > import Pipes.Safe
    > import qualified System.IO as IO
    > import Prelude hiding (readFile)
    >
    > readFile :: FilePath -> Producer' String (SafeT IO) ()
    > readFile file = bracket
    >     (do h <- IO.openFile file IO.ReadMode
    >         putStrLn $ "{" ++ file ++ " open}"
    >         return h )
    >     (\h -> do
    >         IO.hClose h
    >         putStrLn $ "{" ++ file ++ " closed}" )
    >     P.fromHandle

        ... then this generalized 'bracket' will guard against both exceptions and
        premature termination of other pipes:

    >>> runSafeT $ runEffect $ readFile "readFile.hs" >-> P.take 4 >-> P.stdoutLn
    {readFile.hs open}
    -- readFile.hs
    import Pipes
    import qualified Pipes.Prelude as P
    import Pipes.Safe
    {readFile.hs closed}

        Note that the 'MonadCatch' instance for 'Proxy' provides weaker versions of
        'mask' and 'uninterruptibleMask' that do not completely prevent asynchronous
        exceptions.  Instead, they provide a weaker guarantee that asynchronous
        exceptions will only occur during 'Pipes.await's or 'Pipes.yield's and
        nowhere else.  For example, if you write:

    > mask_ $ do
    >     x <- await
    >     lift $ print x
    >     lift $ print x

        ... then you may receive an asynchronous exception during the 'Pipes.await',
        but you will not receive an asynchronous exception during or in between the
        two 'print' statements.  This weaker guarantee suffices to provide
        asynchronous exception safety.
    -}

    module Pipes.Safe
        ( -- * SafeT
          SafeT(SafeT)
        , runSafeT
        , runSafeP

         -- * MonadSafe
        , ReleaseKey
        , MonadSafe(..)

          -- * Utilities
          -- $utilities
        , onException
        , tryP
        , catchP
        , finally
        , bracket
        , bracket_
        , bracketOnError

        -- * Internals
        , Env

        -- * Re-exports
        -- $reexports
        , module Control.Monad.Catch
        , module Control.Exception
        ) where

    import Control.Applicative (Alternative)
    import Control.Exception(Exception(..), SomeException(..))
    import qualified Control.Monad.Catch as C
    import Control.Monad.Catch
        ( MonadCatch(..)
        , MonadThrow(..)
        , MonadMask(..)
        , ExitCase(..)
        , mask_
        , uninterruptibleMask_
        , catchAll
        , catchIOError
        , catchJust
        , catchIf
        , Handler(..)
        , catches
        , handle
        , handleAll
        , handleIOError
        , handleJust
        , handleIf
        , tryJust
        , Exception(..)
        , SomeException
        )
    import Control.Monad (MonadPlus, liftM)
    import Control.Monad.Fix (MonadFix)
    import Control.Monad.IO.Class (MonadIO(liftIO))
    import Control.Monad.Trans.Control (MonadBaseControl(..))
    import Control.Monad.Trans.Class (MonadTrans(lift))
    import qualified Control.Monad.Base                as B
    import qualified Control.Monad.Catch.Pure          as E
    import qualified Control.Monad.Trans.Identity      as I
    import qualified Control.Monad.Cont.Class          as CC
    import qualified Control.Monad.Error.Class         as EC
    import qualified Control.Monad.Primitive           as Prim
    import qualified Control.Monad.Trans.Reader        as R
    import qualified Control.Monad.Trans.RWS.Lazy      as RWS
    import qualified Control.Monad.Trans.RWS.Strict    as RWS'
    import qualified Control.Monad.Trans.State.Lazy    as S
    import qualified Control.Monad.Trans.State.Strict  as S'
    import qualified Control.Monad.State.Class         as SC
    import qualified Control.Monad.Trans.Writer.Lazy   as W
    import qualified Control.Monad.Trans.Writer.Strict as W'
    import qualified Control.Monad.Writer.Class        as WC
    import Data.IORef (IORef, newIORef, readIORef, writeIORef, atomicModifyIORef')
    import Data.Kind (Type)
    import qualified Data.Map as M
    import Pipes (Proxy, Effect, Effect', runEffect)
    import Pipes.Internal (Proxy(..))

    data Restore m = Unmasked | Masked (forall x . m x -> m x)

    liftMask
        :: forall m a' a b' b r . (MonadIO m, MonadCatch m)
        => (forall s . ((forall x . m x -> m x) -> m s) -> m s)
        -> ((forall x . Proxy a' a b' b m x -> Proxy a' a b' b m x)
            -> Proxy a' a b' b m r)
        -> Proxy a' a b' b m r
    liftMask :: forall (m :: * -> *) a' a b' b r.
    (MonadIO m, MonadCatch m) =>
    (forall s. ((forall x. m x -> m x) -> m s) -> m s)
    -> ((forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x)
        -> Proxy a' a b' b m r)
    -> Proxy a' a b' b m r
    liftMask forall s. ((forall x. m x -> m x) -> m s) -> m s
    maskVariant (forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x)
    -> Proxy a' a b' b m r
    k = do
        IORef (Restore m)
    ioref <- IO (IORef (Restore m)) -> Proxy a' a b' b m (IORef (Restore m))
    forall a. IO a -> Proxy a' a b' b m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (IORef (Restore m)) -> Proxy a' a b' b m (IORef (Restore m)))
    -> IO (IORef (Restore m)) -> Proxy a' a b' b m (IORef (Restore m))
    forall a b. (a -> b) -> a -> b
    $ Restore m -> IO (IORef (Restore m))
    forall a. a -> IO (IORef a)
    newIORef Restore m
    forall (m :: * -> *). Restore m
    Unmasked

        let -- mask adjacent actions in base monad
            loop :: Proxy a' a b' b m r -> Proxy a' a b' b m r
            loop :: Proxy a' a b' b m r -> Proxy a' a b' b m r
    loop (Request a'
    a' a -> Proxy a' a b' b m r
    fa ) = a' -> (a -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    forall a' a b' b (m :: * -> *) r.
    a' -> (a -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    Request a'
    a' (Proxy a' a b' b m r -> Proxy a' a b' b m r
    loop (Proxy a' a b' b m r -> Proxy a' a b' b m r)
    -> (a -> Proxy a' a b' b m r) -> a -> Proxy a' a b' b m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Proxy a' a b' b m r
    fa )
            loop (Respond b
    b  b' -> Proxy a' a b' b m r
    fb') = b -> (b' -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    forall a' a b' b (m :: * -> *) r.
    b -> (b' -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    Respond b
    b  (Proxy a' a b' b m r -> Proxy a' a b' b m r
    loop (Proxy a' a b' b m r -> Proxy a' a b' b m r)
    -> (b' -> Proxy a' a b' b m r) -> b' -> Proxy a' a b' b m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . b' -> Proxy a' a b' b m r
    fb')
            loop (M m (Proxy a' a b' b m r)
    m)            = m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
    forall a' a b' b (m :: * -> *) r.
    m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
    M (m (Proxy a' a b' b m r) -> Proxy a' a b' b m r)
    -> m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
    forall a b. (a -> b) -> a -> b
    $ ((forall x. m x -> m x) -> m (Proxy a' a b' b m r))
    -> m (Proxy a' a b' b m r)
    forall s. ((forall x. m x -> m x) -> m s) -> m s
    maskVariant (((forall x. m x -> m x) -> m (Proxy a' a b' b m r))
     -> m (Proxy a' a b' b m r))
    -> ((forall x. m x -> m x) -> m (Proxy a' a b' b m r))
    -> m (Proxy a' a b' b m r)
    forall a b. (a -> b) -> a -> b
    $ \forall x. m x -> m x
    unmaskVariant -> do
                -- stash base's unmask and merge action
                IO () -> m ()
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> m ()) -> IO () -> m ()
    forall a b. (a -> b) -> a -> b
    $ IORef (Restore m) -> Restore m -> IO ()
    forall a. IORef a -> a -> IO ()
    writeIORef IORef (Restore m)
    ioref (Restore m -> IO ()) -> Restore m -> IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall x. m x -> m x) -> Restore m
    forall (m :: * -> *). (forall x. m x -> m x) -> Restore m
    Masked m x -> m x
    forall x. m x -> m x
    unmaskVariant
                m (Proxy a' a b' b m r)
    m m (Proxy a' a b' b m r)
    -> (Proxy a' a b' b m r -> m (Proxy a' a b' b m r))
    -> m (Proxy a' a b' b m r)
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
    forall s. Proxy a' a b' b m s -> m (Proxy a' a b' b m s)
    chunk m (Proxy a' a b' b m r)
    -> (Proxy a' a b' b m r -> m (Proxy a' a b' b m r))
    -> m (Proxy a' a b' b m r)
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Proxy a' a b' b m r -> m (Proxy a' a b' b m r))
    -> (Proxy a' a b' b m r -> Proxy a' a b' b m r)
    -> Proxy a' a b' b m r
    -> m (Proxy a' a b' b m r)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Proxy a' a b' b m r -> Proxy a' a b' b m r
    loop
            loop (Pure r
    r)         = r -> Proxy a' a b' b m r
    forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
    Pure r
    r

            -- unmask adjacent actions in base monad
            unmask :: forall q. Proxy a' a b' b m q -> Proxy a' a b' b m q
            unmask :: forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x
    unmask (Request a'
    a' a -> Proxy a' a b' b m q
    fa ) = a' -> (a -> Proxy a' a b' b m q) -> Proxy a' a b' b m q
    forall a' a b' b (m :: * -> *) r.
    a' -> (a -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    Request a'
    a' (Proxy a' a b' b m q -> Proxy a' a b' b m q
    forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x
    unmask (Proxy a' a b' b m q -> Proxy a' a b' b m q)
    -> (a -> Proxy a' a b' b m q) -> a -> Proxy a' a b' b m q
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Proxy a' a b' b m q
    fa )
            unmask (Respond b
    b  b' -> Proxy a' a b' b m q
    fb') = b -> (b' -> Proxy a' a b' b m q) -> Proxy a' a b' b m q
    forall a' a b' b (m :: * -> *) r.
    b -> (b' -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    Respond b
    b  (Proxy a' a b' b m q -> Proxy a' a b' b m q
    forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x
    unmask (Proxy a' a b' b m q -> Proxy a' a b' b m q)
    -> (b' -> Proxy a' a b' b m q) -> b' -> Proxy a' a b' b m q
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . b' -> Proxy a' a b' b m q
    fb')
            unmask (M m (Proxy a' a b' b m q)
    m)            = m (Proxy a' a b' b m q) -> Proxy a' a b' b m q
    forall a' a b' b (m :: * -> *) r.
    m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
    M (m (Proxy a' a b' b m q) -> Proxy a' a b' b m q)
    -> m (Proxy a' a b' b m q) -> Proxy a' a b' b m q
    forall a b. (a -> b) -> a -> b
    $ do
                -- retrieve base's unmask and apply to merged action
                m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q)
    unmaskVariant <- IO (m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q))
    -> m (m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q))
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q))
     -> m (m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q)))
    -> IO (m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q))
    -> m (m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q))
    forall a b. (a -> b) -> a -> b
    $ do
                    Masked forall x. m x -> m x
    unmaskVariant <- IORef (Restore m) -> IO (Restore m)
    forall a. IORef a -> IO a
    readIORef IORef (Restore m)
    ioref
                    (m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q))
    -> IO (m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q)
    forall x. m x -> m x
    unmaskVariant
                m (Proxy a' a b' b m q) -> m (Proxy a' a b' b m q)
    unmaskVariant (m (Proxy a' a b' b m q)
    m m (Proxy a' a b' b m q)
    -> (Proxy a' a b' b m q -> m (Proxy a' a b' b m q))
    -> m (Proxy a' a b' b m q)
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Proxy a' a b' b m q -> m (Proxy a' a b' b m q)
    forall s. Proxy a' a b' b m s -> m (Proxy a' a b' b m s)
    chunk m (Proxy a' a b' b m q)
    -> (Proxy a' a b' b m q -> m (Proxy a' a b' b m q))
    -> m (Proxy a' a b' b m q)
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Proxy a' a b' b m q -> m (Proxy a' a b' b m q)
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Proxy a' a b' b m q -> m (Proxy a' a b' b m q))
    -> (Proxy a' a b' b m q -> Proxy a' a b' b m q)
    -> Proxy a' a b' b m q
    -> m (Proxy a' a b' b m q)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Proxy a' a b' b m q -> Proxy a' a b' b m q
    forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x
    unmask)
            unmask (Pure q
    q)         = q -> Proxy a' a b' b m q
    forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
    Pure q
    q

            -- merge adjacent actions in base monad
            chunk :: forall s. Proxy a' a b' b m s -> m (Proxy a' a b' b m s)
            chunk :: forall s. Proxy a' a b' b m s -> m (Proxy a' a b' b m s)
    chunk (M m (Proxy a' a b' b m s)
    m) = m (Proxy a' a b' b m s)
    m m (Proxy a' a b' b m s)
    -> (Proxy a' a b' b m s -> m (Proxy a' a b' b m s))
    -> m (Proxy a' a b' b m s)
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Proxy a' a b' b m s -> m (Proxy a' a b' b m s)
    forall s. Proxy a' a b' b m s -> m (Proxy a' a b' b m s)
    chunk
            chunk Proxy a' a b' b m s
    s     = Proxy a' a b' b m s -> m (Proxy a' a b' b m s)
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Proxy a' a b' b m s
    s

        Proxy a' a b' b m r -> Proxy a' a b' b m r
    loop (Proxy a' a b' b m r -> Proxy a' a b' b m r)
    -> Proxy a' a b' b m r -> Proxy a' a b' b m r
    forall a b. (a -> b) -> a -> b
    $ (forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x)
    -> Proxy a' a b' b m r
    k Proxy a' a b' b m x -> Proxy a' a b' b m x
    forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x
    unmask

    instance (MonadMask m, MonadIO m) => MonadMask (Proxy a' a b' b m) where
        mask :: forall b.
    HasCallStack =>
    ((forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a)
     -> Proxy a' a b' b m b)
    -> Proxy a' a b' b m b
    mask = (forall s. ((forall x. m x -> m x) -> m s) -> m s)
    -> ((forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a)
        -> Proxy a' a b' b m b)
    -> Proxy a' a b' b m b
    forall (m :: * -> *) a' a b' b r.
    (MonadIO m, MonadCatch m) =>
    (forall s. ((forall x. m x -> m x) -> m s) -> m s)
    -> ((forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x)
        -> Proxy a' a b' b m r)
    -> Proxy a' a b' b m r
    liftMask ((forall x. m x -> m x) -> m s) -> m s
    forall b. HasCallStack => ((forall x. m x -> m x) -> m b) -> m b
    forall s. ((forall x. m x -> m x) -> m s) -> m s
    forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. m a -> m a) -> m b) -> m b
    mask

        uninterruptibleMask :: forall b.
    HasCallStack =>
    ((forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a)
     -> Proxy a' a b' b m b)
    -> Proxy a' a b' b m b
    uninterruptibleMask = (forall s. ((forall x. m x -> m x) -> m s) -> m s)
    -> ((forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a)
        -> Proxy a' a b' b m b)
    -> Proxy a' a b' b m b
    forall (m :: * -> *) a' a b' b r.
    (MonadIO m, MonadCatch m) =>
    (forall s. ((forall x. m x -> m x) -> m s) -> m s)
    -> ((forall x. Proxy a' a b' b m x -> Proxy a' a b' b m x)
        -> Proxy a' a b' b m r)
    -> Proxy a' a b' b m r
    liftMask ((forall x. m x -> m x) -> m s) -> m s
    forall b. HasCallStack => ((forall x. m x -> m x) -> m b) -> m b
    forall s. ((forall x. m x -> m x) -> m s) -> m s
    forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. m a -> m a) -> m b) -> m b
    uninterruptibleMask

        generalBracket :: forall a b c.
    HasCallStack =>
    Proxy a' a b' b m a
    -> (a -> ExitCase b -> Proxy a' a b' b m c)
    -> (a -> Proxy a' a b' b m b)
    -> Proxy a' a b' b m (b, c)
    generalBracket Proxy a' a b' b m a
    acquire a -> ExitCase b -> Proxy a' a b' b m c
    release_ a -> Proxy a' a b' b m b
    use = ((forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a)
     -> Proxy a' a b' b m (b, c))
    -> Proxy a' a b' b m (b, c)
    forall b.
    HasCallStack =>
    ((forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a)
     -> Proxy a' a b' b m b)
    -> Proxy a' a b' b m b
    forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. m a -> m a) -> m b) -> m b
    mask (((forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a)
      -> Proxy a' a b' b m (b, c))
     -> Proxy a' a b' b m (b, c))
    -> ((forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a)
        -> Proxy a' a b' b m (b, c))
    -> Proxy a' a b' b m (b, c)
    forall a b. (a -> b) -> a -> b
    $ \forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a
    unmasked -> do
          a
    a <- Proxy a' a b' b m a
    acquire
          let action :: Proxy a' a b' b m (ExitCase b, ExitCase_ b)
    action = do
                  b
    b <- a -> Proxy a' a b' b m b
    use a
    a
                  (ExitCase b, ExitCase_ b)
    -> Proxy a' a b' b m (ExitCase b, ExitCase_ b)
    forall a. a -> Proxy a' a b' b m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (b -> ExitCase b
    forall a. a -> ExitCase a
    ExitCaseSuccess b
    b, b -> ExitCase_ b
    forall a. a -> ExitCase_ a
    ExitCaseSuccess_ b
    b)
          let handler :: SomeException -> m (ExitCase a, ExitCase_ a)
    handler SomeException
    e = (ExitCase a, ExitCase_ a) -> m (ExitCase a, ExitCase_ a)
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (SomeException -> ExitCase a
    forall a. SomeException -> ExitCase a
    ExitCaseException SomeException
    e, SomeException -> ExitCase_ a
    forall a. SomeException -> ExitCase_ a
    ExitCaseException_ SomeException
    e)
          (ExitCase b
    exitCase, ExitCase_ b
    exitCase_) <- Proxy a' a b' b m (ExitCase b, ExitCase_ b)
    -> Proxy a' a b' b m (ExitCase b, ExitCase_ b)
    forall a. Proxy a' a b' b m a -> Proxy a' a b' b m a
    unmasked Proxy a' a b' b m (ExitCase b, ExitCase_ b)
    action Proxy a' a b' b m (ExitCase b, ExitCase_ b)
    -> (SomeException -> Proxy a' a b' b m (ExitCase b, ExitCase_ b))
    -> Proxy a' a b' b m (ExitCase b, ExitCase_ b)
    forall e a.
    (HasCallStack, Exception e) =>
    Proxy a' a b' b m a
    -> (e -> Proxy a' a b' b m a) -> Proxy a' a b' b m a
    forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    m a -> (e -> m a) -> m a
    `catch` SomeException -> Proxy a' a b' b m (ExitCase b, ExitCase_ b)
    forall {m :: * -> *} {a} {a}.
    Monad m =>
    SomeException -> m (ExitCase a, ExitCase_ a)
    handler
          c
    c <- a -> ExitCase b -> Proxy a' a b' b m c
    release_ a
    a ExitCase b
    exitCase
          case ExitCase_ b
    exitCase_ of
              ExitCaseException_ SomeException
    e -> SomeException -> Proxy a' a b' b m (b, c)
    forall e a. (HasCallStack, Exception e) => e -> Proxy a' a b' b m a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM SomeException
    e
              ExitCaseSuccess_ b
    b   -> (b, c) -> Proxy a' a b' b m (b, c)
    forall a. a -> Proxy a' a b' b m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (b
    b, c
    c)

    -- | This is to avoid an unnecessary partial pattern match in `generalBracket`
    data ExitCase_ a = ExitCaseSuccess_ a | ExitCaseException_ SomeException

    data Finalizers m = Finalizers
        { forall (m :: * -> *). Finalizers m -> Integer
    _nextKey    :: !Integer
        , forall (m :: * -> *). Finalizers m -> Map Integer (m ())
    _finalizers :: !(M.Map Integer (m ()))
        }

    -- | Internal 'SafeT' read-write environment. Exported only so that it can be
    -- passed around unmodified by users of the v'SafeT' constructor.
    --
    -- Warning: Using the 'Env' outside the corresponding 'SafeT' scope will
    -- result in undefined behavior.
    newtype Env m = Env (IORef (Maybe (Finalizers m)))

    {-| 'SafeT' is a monad transformer that extends the base monad with the ability
        to 'register' and 'release' finalizers.

        All unreleased finalizers are called at the end of the 'SafeT' block, even
        in the event of exceptions.
    -}
    newtype SafeT m r
        = -- | Constructor exported in case it's necessary for integrating 'SafeT'
          -- with other libraries. For example, implementing @mtl@-like
          -- Monad/Something/ instances will often require access to the 'SafeT'
          -- constructor.
          --
          -- Warning: Using the 'Env' outside the corresponding 'SafeT' scope will
          -- result in undefined behavior.
          SafeT (R.ReaderT (Env m) m r)
        deriving
        ( (forall a b. (a -> b) -> SafeT m a -> SafeT m b)
    -> (forall a b. a -> SafeT m b -> SafeT m a) -> Functor (SafeT m)
    forall a b. a -> SafeT m b -> SafeT m a
    forall a b. (a -> b) -> SafeT m a -> SafeT m b
    forall (m :: * -> *) a b. Functor m => a -> SafeT m b -> SafeT m a
    forall (m :: * -> *) a b.
    Functor m =>
    (a -> b) -> SafeT m a -> SafeT m b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall (m :: * -> *) a b.
    Functor m =>
    (a -> b) -> SafeT m a -> SafeT m b
    fmap :: forall a b. (a -> b) -> SafeT m a -> SafeT m b
    $c<$ :: forall (m :: * -> *) a b. Functor m => a -> SafeT m b -> SafeT m a
    <$ :: forall a b. a -> SafeT m b -> SafeT m a
    Functor
        , Functor (SafeT m)
    Functor (SafeT m) =>
    (forall a. a -> SafeT m a)
    -> (forall a b. SafeT m (a -> b) -> SafeT m a -> SafeT m b)
    -> (forall a b c.
        (a -> b -> c) -> SafeT m a -> SafeT m b -> SafeT m c)
    -> (forall a b. SafeT m a -> SafeT m b -> SafeT m b)
    -> (forall a b. SafeT m a -> SafeT m b -> SafeT m a)
    -> Applicative (SafeT m)
    forall a. a -> SafeT m a
    forall a b. SafeT m a -> SafeT m b -> SafeT m a
    forall a b. SafeT m a -> SafeT m b -> SafeT m b
    forall a b. SafeT m (a -> b) -> SafeT m a -> SafeT m b
    forall a b c. (a -> b -> c) -> SafeT m a -> SafeT m b -> SafeT m c
    forall (f :: * -> *).
    Functor f =>
    (forall a. a -> f a)
    -> (forall a b. f (a -> b) -> f a -> f b)
    -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
    -> (forall a b. f a -> f b -> f b)
    -> (forall a b. f a -> f b -> f a)
    -> Applicative f
    forall (m :: * -> *). Applicative m => Functor (SafeT m)
    forall (m :: * -> *) a. Applicative m => a -> SafeT m a
    forall (m :: * -> *) a b.
    Applicative m =>
    SafeT m a -> SafeT m b -> SafeT m a
    forall (m :: * -> *) a b.
    Applicative m =>
    SafeT m a -> SafeT m b -> SafeT m b
    forall (m :: * -> *) a b.
    Applicative m =>
    SafeT m (a -> b) -> SafeT m a -> SafeT m b
    forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> c) -> SafeT m a -> SafeT m b -> SafeT m c
    $cpure :: forall (m :: * -> *) a. Applicative m => a -> SafeT m a
    pure :: forall a. a -> SafeT m a
    $c<*> :: forall (m :: * -> *) a b.
    Applicative m =>
    SafeT m (a -> b) -> SafeT m a -> SafeT m b
    <*> :: forall a b. SafeT m (a -> b) -> SafeT m a -> SafeT m b
    $cliftA2 :: forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> c) -> SafeT m a -> SafeT m b -> SafeT m c
    liftA2 :: forall a b c. (a -> b -> c) -> SafeT m a -> SafeT m b -> SafeT m c
    $c*> :: forall (m :: * -> *) a b.
    Applicative m =>
    SafeT m a -> SafeT m b -> SafeT m b
    *> :: forall a b. SafeT m a -> SafeT m b -> SafeT m b
    $c<* :: forall (m :: * -> *) a b.
    Applicative m =>
    SafeT m a -> SafeT m b -> SafeT m a
    <* :: forall a b. SafeT m a -> SafeT m b -> SafeT m a
    Applicative
        , Applicative (SafeT m)
    Applicative (SafeT m) =>
    (forall a. SafeT m a)
    -> (forall a. SafeT m a -> SafeT m a -> SafeT m a)
    -> (forall a. SafeT m a -> SafeT m [a])
    -> (forall a. SafeT m a -> SafeT m [a])
    -> Alternative (SafeT m)
    forall a. SafeT m a
    forall a. SafeT m a -> SafeT m [a]
    forall a. SafeT m a -> SafeT m a -> SafeT m a
    forall (f :: * -> *).
    Applicative f =>
    (forall a. f a)
    -> (forall a. f a -> f a -> f a)
    -> (forall a. f a -> f [a])
    -> (forall a. f a -> f [a])
    -> Alternative f
    forall (m :: * -> *). Alternative m => Applicative (SafeT m)
    forall (m :: * -> *) a. Alternative m => SafeT m a
    forall (m :: * -> *) a. Alternative m => SafeT m a -> SafeT m [a]
    forall (m :: * -> *) a.
    Alternative m =>
    SafeT m a -> SafeT m a -> SafeT m a
    $cempty :: forall (m :: * -> *) a. Alternative m => SafeT m a
    empty :: forall a. SafeT m a
    $c<|> :: forall (m :: * -> *) a.
    Alternative m =>
    SafeT m a -> SafeT m a -> SafeT m a
    <|> :: forall a. SafeT m a -> SafeT m a -> SafeT m a
    $csome :: forall (m :: * -> *) a. Alternative m => SafeT m a -> SafeT m [a]
    some :: forall a. SafeT m a -> SafeT m [a]
    $cmany :: forall (m :: * -> *) a. Alternative m => SafeT m a -> SafeT m [a]
    many :: forall a. SafeT m a -> SafeT m [a]
    Alternative
        , Applicative (SafeT m)
    Applicative (SafeT m) =>
    (forall a b. SafeT m a -> (a -> SafeT m b) -> SafeT m b)
    -> (forall a b. SafeT m a -> SafeT m b -> SafeT m b)
    -> (forall a. a -> SafeT m a)
    -> Monad (SafeT m)
    forall a. a -> SafeT m a
    forall a b. SafeT m a -> SafeT m b -> SafeT m b
    forall a b. SafeT m a -> (a -> SafeT m b) -> SafeT m b
    forall (m :: * -> *). Monad m => Applicative (SafeT m)
    forall (m :: * -> *) a. Monad m => a -> SafeT m a
    forall (m :: * -> *) a b.
    Monad m =>
    SafeT m a -> SafeT m b -> SafeT m b
    forall (m :: * -> *) a b.
    Monad m =>
    SafeT m a -> (a -> SafeT m b) -> SafeT m b
    forall (m :: * -> *).
    Applicative m =>
    (forall a b. m a -> (a -> m b) -> m b)
    -> (forall a b. m a -> m b -> m b)
    -> (forall a. a -> m a)
    -> Monad m
    $c>>= :: forall (m :: * -> *) a b.
    Monad m =>
    SafeT m a -> (a -> SafeT m b) -> SafeT m b
    >>= :: forall a b. SafeT m a -> (a -> SafeT m b) -> SafeT m b
    $c>> :: forall (m :: * -> *) a b.
    Monad m =>
    SafeT m a -> SafeT m b -> SafeT m b
    >> :: forall a b. SafeT m a -> SafeT m b -> SafeT m b
    $creturn :: forall (m :: * -> *) a. Monad m => a -> SafeT m a
    return :: forall a. a -> SafeT m a
    Monad
    -- The derived instance for `MonadFail` requires a `MonadFail` instance for
    -- `ReaderT` which is first available in `transformers-0.5.0.0`
        , Monad (SafeT m)
    Monad (SafeT m) =>
    (forall a. String -> SafeT m a) -> MonadFail (SafeT m)
    forall a. String -> SafeT m a
    forall (m :: * -> *).
    Monad m =>
    (forall a. String -> m a) -> MonadFail m
    forall (m :: * -> *). MonadFail m => Monad (SafeT m)
    forall (m :: * -> *) a. MonadFail m => String -> SafeT m a
    $cfail :: forall (m :: * -> *) a. MonadFail m => String -> SafeT m a
    fail :: forall a. String -> SafeT m a
    MonadFail
        , Monad (SafeT m)
    Alternative (SafeT m)
    (Alternative (SafeT m), Monad (SafeT m)) =>
    (forall a. SafeT m a)
    -> (forall a. SafeT m a -> SafeT m a -> SafeT m a)
    -> MonadPlus (SafeT m)
    forall a. SafeT m a
    forall a. SafeT m a -> SafeT m a -> SafeT m a
    forall (m :: * -> *). MonadPlus m => Monad (SafeT m)
    forall (m :: * -> *). MonadPlus m => Alternative (SafeT m)
    forall (m :: * -> *) a. MonadPlus m => SafeT m a
    forall (m :: * -> *) a.
    MonadPlus m =>
    SafeT m a -> SafeT m a -> SafeT m a
    forall (m :: * -> *).
    (Alternative m, Monad m) =>
    (forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
    $cmzero :: forall (m :: * -> *) a. MonadPlus m => SafeT m a
    mzero :: forall a. SafeT m a
    $cmplus :: forall (m :: * -> *) a.
    MonadPlus m =>
    SafeT m a -> SafeT m a -> SafeT m a
    mplus :: forall a. SafeT m a -> SafeT m a -> SafeT m a
    MonadPlus
        , Monad (SafeT m)
    Monad (SafeT m) =>
    (forall a. (a -> SafeT m a) -> SafeT m a) -> MonadFix (SafeT m)
    forall a. (a -> SafeT m a) -> SafeT m a
    forall (m :: * -> *).
    Monad m =>
    (forall a. (a -> m a) -> m a) -> MonadFix m
    forall (m :: * -> *). MonadFix m => Monad (SafeT m)
    forall (m :: * -> *) a. MonadFix m => (a -> SafeT m a) -> SafeT m a
    $cmfix :: forall (m :: * -> *) a. MonadFix m => (a -> SafeT m a) -> SafeT m a
    mfix :: forall a. (a -> SafeT m a) -> SafeT m a
    MonadFix
        , EC.MonadError e
        , SC.MonadState s
        , WC.MonadWriter w
        , Monad (SafeT m)
    Monad (SafeT m) =>
    (forall a b. ((a -> SafeT m b) -> SafeT m a) -> SafeT m a)
    -> MonadCont (SafeT m)
    forall a b. ((a -> SafeT m b) -> SafeT m a) -> SafeT m a
    forall (m :: * -> *).
    Monad m =>
    (forall a b. ((a -> m b) -> m a) -> m a) -> MonadCont m
    forall (m :: * -> *). MonadCont m => Monad (SafeT m)
    forall (m :: * -> *) a b.
    MonadCont m =>
    ((a -> SafeT m b) -> SafeT m a) -> SafeT m a
    $ccallCC :: forall (m :: * -> *) a b.
    MonadCont m =>
    ((a -> SafeT m b) -> SafeT m a) -> SafeT m a
    callCC :: forall a b. ((a -> SafeT m b) -> SafeT m a) -> SafeT m a
    CC.MonadCont
        , Monad (SafeT m)
    Monad (SafeT m) =>
    (forall e a. (HasCallStack, Exception e) => e -> SafeT m a)
    -> MonadThrow (SafeT m)
    forall e a. (HasCallStack, Exception e) => e -> SafeT m a
    forall (m :: * -> *).
    Monad m =>
    (forall e a. (HasCallStack, Exception e) => e -> m a)
    -> MonadThrow m
    forall (m :: * -> *). MonadThrow m => Monad (SafeT m)
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> SafeT m a
    $cthrowM :: forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> SafeT m a
    throwM :: forall e a. (HasCallStack, Exception e) => e -> SafeT m a
    MonadThrow
        , MonadThrow (SafeT m)
    MonadThrow (SafeT m) =>
    (forall e a.
     (HasCallStack, Exception e) =>
     SafeT m a -> (e -> SafeT m a) -> SafeT m a)
    -> MonadCatch (SafeT m)
    forall e a.
    (HasCallStack, Exception e) =>
    SafeT m a -> (e -> SafeT m a) -> SafeT m a
    forall (m :: * -> *). MonadCatch m => MonadThrow (SafeT m)
    forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    SafeT m a -> (e -> SafeT m a) -> SafeT m a
    forall (m :: * -> *).
    MonadThrow m =>
    (forall e a.
     (HasCallStack, Exception e) =>
     m a -> (e -> m a) -> m a)
    -> MonadCatch m
    $ccatch :: forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    SafeT m a -> (e -> SafeT m a) -> SafeT m a
    catch :: forall e a.
    (HasCallStack, Exception e) =>
    SafeT m a -> (e -> SafeT m a) -> SafeT m a
    MonadCatch
        , MonadCatch (SafeT m)
    MonadCatch (SafeT m) =>
    (forall b.
     HasCallStack =>
     ((forall a. SafeT m a -> SafeT m a) -> SafeT m b) -> SafeT m b)
    -> (forall b.
        HasCallStack =>
        ((forall a. SafeT m a -> SafeT m a) -> SafeT m b) -> SafeT m b)
    -> (forall a b c.
        HasCallStack =>
        SafeT m a
        -> (a -> ExitCase b -> SafeT m c)
        -> (a -> SafeT m b)
        -> SafeT m (b, c))
    -> MonadMask (SafeT m)
    forall b.
    HasCallStack =>
    ((forall a. SafeT m a -> SafeT m a) -> SafeT m b) -> SafeT m b
    forall a b c.
    HasCallStack =>
    SafeT m a
    -> (a -> ExitCase b -> SafeT m c)
    -> (a -> SafeT m b)
    -> SafeT m (b, c)
    forall (m :: * -> *). MonadMask m => MonadCatch (SafeT m)
    forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. SafeT m a -> SafeT m a) -> SafeT m b) -> SafeT m b
    forall (m :: * -> *) a b c.
    (MonadMask m, HasCallStack) =>
    SafeT m a
    -> (a -> ExitCase b -> SafeT m c)
    -> (a -> SafeT m b)
    -> SafeT m (b, c)
    forall (m :: * -> *).
    MonadCatch m =>
    (forall b. HasCallStack => ((forall a. m a -> m a) -> m b) -> m b)
    -> (forall b.
        HasCallStack =>
        ((forall a. m a -> m a) -> m b) -> m b)
    -> (forall a b c.
        HasCallStack =>
        m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
    -> MonadMask m
    $cmask :: forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. SafeT m a -> SafeT m a) -> SafeT m b) -> SafeT m b
    mask :: forall b.
    HasCallStack =>
    ((forall a. SafeT m a -> SafeT m a) -> SafeT m b) -> SafeT m b
    $cuninterruptibleMask :: forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. SafeT m a -> SafeT m a) -> SafeT m b) -> SafeT m b
    uninterruptibleMask :: forall b.
    HasCallStack =>
    ((forall a. SafeT m a -> SafeT m a) -> SafeT m b) -> SafeT m b
    $cgeneralBracket :: forall (m :: * -> *) a b c.
    (MonadMask m, HasCallStack) =>
    SafeT m a
    -> (a -> ExitCase b -> SafeT m c)
    -> (a -> SafeT m b)
    -> SafeT m (b, c)
    generalBracket :: forall a b c.
    HasCallStack =>
    SafeT m a
    -> (a -> ExitCase b -> SafeT m c)
    -> (a -> SafeT m b)
    -> SafeT m (b, c)
    MonadMask
        , Monad (SafeT m)
    Monad (SafeT m) =>
    (forall a. IO a -> SafeT m a) -> MonadIO (SafeT m)
    forall a. IO a -> SafeT m a
    forall (m :: * -> *).
    Monad m =>
    (forall a. IO a -> m a) -> MonadIO m
    forall (m :: * -> *). MonadIO m => Monad (SafeT m)
    forall (m :: * -> *) a. MonadIO m => IO a -> SafeT m a
    $cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> SafeT m a
    liftIO :: forall a. IO a -> SafeT m a
    MonadIO
        , B.MonadBase b
        )

    instance MonadTrans SafeT where
        lift :: forall (m :: * -> *) a. Monad m => m a -> SafeT m a
    lift m a
    m = ReaderT (Env m) m a -> SafeT m a
    forall (m :: * -> *) r. ReaderT (Env m) m r -> SafeT m r
    SafeT (m a -> ReaderT (Env m) m a
    forall (m :: * -> *) a. Monad m => m a -> ReaderT (Env m) m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift m a
    m)

    instance MonadBaseControl b m => MonadBaseControl b (SafeT m) where
         type StM (SafeT m) a = StM m a
         liftBaseWith :: forall a. (RunInBase (SafeT m) b -> b a) -> SafeT m a
    liftBaseWith RunInBase (SafeT m) b -> b a
    f = ReaderT (Env m) m a -> SafeT m a
    forall (m :: * -> *) r. ReaderT (Env m) m r -> SafeT m r
    SafeT (ReaderT (Env m) m a -> SafeT m a)
    -> ReaderT (Env m) m a -> SafeT m a
    forall a b. (a -> b) -> a -> b
    $ (Env m -> m a) -> ReaderT (Env m) m a
    forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
    R.ReaderT ((Env m -> m a) -> ReaderT (Env m) m a)
    -> (Env m -> m a) -> ReaderT (Env m) m a
    forall a b. (a -> b) -> a -> b
    $ \Env m
    reader' ->
             (RunInBase m b -> b a) -> m a
    forall a. (RunInBase m b -> b a) -> m a
    forall (b :: * -> *) (m :: * -> *) a.
    MonadBaseControl b m =>
    (RunInBase m b -> b a) -> m a
    liftBaseWith ((RunInBase m b -> b a) -> m a) -> (RunInBase m b -> b a) -> m a
    forall a b. (a -> b) -> a -> b
    $ \RunInBase m b
    runInBase ->
                 RunInBase (SafeT m) b -> b a
    f (RunInBase (SafeT m) b -> b a) -> RunInBase (SafeT m) b -> b a
    forall a b. (a -> b) -> a -> b
    $ m a -> b (StM m a)
    RunInBase m b
    runInBase (m a -> b (StM m a))
    -> (SafeT m a -> m a) -> SafeT m a -> b (StM m a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (\(SafeT ReaderT (Env m) m a
    r) -> ReaderT (Env m) m a -> Env m -> m a
    forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    R.runReaderT ReaderT (Env m) m a
    r Env m
    reader'  )
         restoreM :: forall a. StM (SafeT m) a -> SafeT m a
    restoreM = ReaderT (Env m) m a -> SafeT m a
    forall (m :: * -> *) r. ReaderT (Env m) m r -> SafeT m r
    SafeT (ReaderT (Env m) m a -> SafeT m a)
    -> (StM m a -> ReaderT (Env m) m a) -> StM m a -> SafeT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Env m -> m a) -> ReaderT (Env m) m a
    forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
    R.ReaderT ((Env m -> m a) -> ReaderT (Env m) m a)
    -> (StM m a -> Env m -> m a) -> StM m a -> ReaderT (Env m) m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m a -> Env m -> m a
    forall a b. a -> b -> a
    const (m a -> Env m -> m a)
    -> (StM m a -> m a) -> StM m a -> Env m -> m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StM m a -> m a
    forall a. StM m a -> m a
    forall (b :: * -> *) (m :: * -> *) a.
    MonadBaseControl b m =>
    StM m a -> m a
    restoreM

    instance Prim.PrimMonad m => Prim.PrimMonad (SafeT m) where
      type PrimState (SafeT m) = Prim.PrimState m
      primitive :: forall a.
    (State# (PrimState (SafeT m))
     -> (# State# (PrimState (SafeT m)), a #))
    -> SafeT m a
    primitive = m a -> SafeT m a
    forall (m :: * -> *) a. Monad m => m a -> SafeT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> SafeT m a)
    -> ((State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
    -> (State# (PrimState m) -> (# State# (PrimState m), a #))
    -> SafeT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
    forall a.
    (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
    forall (m :: * -> *) a.
    PrimMonad m =>
    (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
    Prim.primitive
      {-# INLINE primitive #-}

    {-| Run the 'SafeT' monad transformer, executing all unreleased finalizers at
        the end of the computation
    -}
    runSafeT :: (MonadMask m, MonadIO m) => SafeT m r -> m r
    runSafeT :: forall (m :: * -> *) r.
    (MonadMask m, MonadIO m) =>
    SafeT m r -> m r
    runSafeT (SafeT ReaderT (Env m) m r
    m) = m (IORef (Maybe (Finalizers m)))
    -> (IORef (Maybe (Finalizers m)) -> m [()])
    -> (IORef (Maybe (Finalizers m)) -> m r)
    -> m r
    forall (m :: * -> *) a c b.
    (HasCallStack, MonadMask m) =>
    m a -> (a -> m c) -> (a -> m b) -> m b
    C.bracket
        (IO (IORef (Maybe (Finalizers m)))
    -> m (IORef (Maybe (Finalizers m)))
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (IORef (Maybe (Finalizers m)))
     -> m (IORef (Maybe (Finalizers m))))
    -> IO (IORef (Maybe (Finalizers m)))
    -> m (IORef (Maybe (Finalizers m)))
    forall a b. (a -> b) -> a -> b
    $ Maybe (Finalizers m) -> IO (IORef (Maybe (Finalizers m)))
    forall a. a -> IO (IORef a)
    newIORef (Maybe (Finalizers m) -> IO (IORef (Maybe (Finalizers m))))
    -> Maybe (Finalizers m) -> IO (IORef (Maybe (Finalizers m)))
    forall a b. (a -> b) -> a -> b
    $! Finalizers m -> Maybe (Finalizers m)
    forall a. a -> Maybe a
    Just (Finalizers m -> Maybe (Finalizers m))
    -> Finalizers m -> Maybe (Finalizers m)
    forall a b. (a -> b) -> a -> b
    $! Integer -> Map Integer (m ()) -> Finalizers m
    forall (m :: * -> *). Integer -> Map Integer (m ()) -> Finalizers m
    Finalizers Integer
    0 Map Integer (m ())
    forall k a. Map k a
    M.empty)
        (\IORef (Maybe (Finalizers m))
    ioref -> do
            Maybe (Finalizers m)
    mres <- IO (Maybe (Finalizers m)) -> m (Maybe (Finalizers m))
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (Maybe (Finalizers m)) -> m (Maybe (Finalizers m)))
    -> IO (Maybe (Finalizers m)) -> m (Maybe (Finalizers m))
    forall a b. (a -> b) -> a -> b
    $ IORef (Maybe (Finalizers m))
    -> (Maybe (Finalizers m)
        -> (Maybe (Finalizers m), Maybe (Finalizers m)))
    -> IO (Maybe (Finalizers m))
    forall a b. IORef a -> (a -> (a, b)) -> IO b
    atomicModifyIORef' IORef (Maybe (Finalizers m))
    ioref ((Maybe (Finalizers m)
      -> (Maybe (Finalizers m), Maybe (Finalizers m)))
     -> IO (Maybe (Finalizers m)))
    -> (Maybe (Finalizers m)
        -> (Maybe (Finalizers m), Maybe (Finalizers m)))
    -> IO (Maybe (Finalizers m))
    forall a b. (a -> b) -> a -> b
    $ \Maybe (Finalizers m)
    val ->
                (Maybe (Finalizers m)
    forall a. Maybe a
    Nothing, Maybe (Finalizers m)
    val)
            case Maybe (Finalizers m)
    mres of
                Maybe (Finalizers m)
    Nothing -> String -> m [()]
    forall a. HasCallStack => String -> a
    error String
    "runSafeT's resources were freed by another"
                Just (Finalizers Integer
    _ Map Integer (m ())
    fs) -> ((Integer, m ()) -> m ()) -> [(Integer, m ())] -> m [()]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM (Integer, m ()) -> m ()
    forall a b. (a, b) -> b
    snd (Map Integer (m ()) -> [(Integer, m ())]
    forall k a. Map k a -> [(k, a)]
    M.toDescList Map Integer (m ())
    fs) )
        (ReaderT (Env m) m r -> Env m -> m r
    forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    R.runReaderT ReaderT (Env m) m r
    m (Env m -> m r)
    -> (IORef (Maybe (Finalizers m)) -> Env m)
    -> IORef (Maybe (Finalizers m))
    -> m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . IORef (Maybe (Finalizers m)) -> Env m
    forall (m :: * -> *). IORef (Maybe (Finalizers m)) -> Env m
    Env)
    {-# INLINABLE runSafeT #-}

    {-| Run 'SafeT' in the base monad, executing all unreleased finalizers at the
        end of the computation

        Use 'runSafeP' to safely flush all unreleased finalizers and ensure prompt
        finalization without exiting the 'Proxy' monad.
    -}
    runSafeP :: (MonadMask m, MonadIO m) => Effect (SafeT m) r -> Effect' m r
    runSafeP :: forall (m :: * -> *) r.
    (MonadMask m, MonadIO m) =>
    Effect (SafeT m) r -> Effect' m r
    runSafeP Effect (SafeT m) r
    e = m r -> Proxy x' x y' y m r
    forall (m :: * -> *) a. Monad m => m a -> Proxy x' x y' y m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> Proxy x' x y' y m r)
    -> (Effect (SafeT m) r -> m r)
    -> Effect (SafeT m) r
    -> Proxy x' x y' y m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SafeT m r -> m r
    forall (m :: * -> *) r.
    (MonadMask m, MonadIO m) =>
    SafeT m r -> m r
    runSafeT (SafeT m r -> m r)
    -> (Effect (SafeT m) r -> SafeT m r) -> Effect (SafeT m) r -> m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Effect (SafeT m) r -> SafeT m r
    forall (m :: * -> *) r. Monad m => Effect m r -> m r
    runEffect (Effect (SafeT m) r -> Proxy x' x y' y m r)
    -> Effect (SafeT m) r -> Proxy x' x y' y m r
    forall a b. (a -> b) -> a -> b
    $ Effect (SafeT m) r
    e
    {-# INLINABLE runSafeP #-}

    -- | Token used to 'release' a previously 'register'ed finalizer
    newtype ReleaseKey = ReleaseKey { ReleaseKey -> Integer
    unlock :: Integer }

    {-| 'MonadSafe' lets you 'register' and 'release' finalizers that execute in a
        'Base' monad
    -}
    class (MonadCatch m, MonadMask m, MonadIO m, MonadIO (Base m)) => MonadSafe m where
        {-| The monad used to run resource management actions, corresponding to the
            monad directly beneath 'SafeT'
        -}
        type Base (m :: Type -> Type) :: Type -> Type

        -- | Lift an action from the 'Base' monad
        liftBase :: Base m r -> m r

        {-| 'register' a finalizer, ensuring that the finalizer gets called if the
            finalizer is not 'release'd before the end of the surrounding 'SafeT'
            block.
        -}
        register :: Base m () -> m ReleaseKey

        {-| 'release' a registered finalizer

            You can safely call 'release' more than once on the same 'ReleaseKey'.
            Every 'release' after the first one does nothing.
        -}
        release  :: ReleaseKey -> m ()

    instance (MonadIO m, MonadCatch m, MonadMask m) => MonadSafe (SafeT m) where
        type Base (SafeT m) = m

        liftBase :: forall r. Base (SafeT m) r -> SafeT m r
    liftBase = m r -> SafeT m r
    Base (SafeT m) r -> SafeT m r
    forall (m :: * -> *) a. Monad m => m a -> SafeT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift

        register :: Base (SafeT m) () -> SafeT m ReleaseKey
    register Base (SafeT m) ()
    io = do
            Env IORef (Maybe (Finalizers m))
    ioref <- ReaderT (Env m) m (Env m) -> SafeT m (Env m)
    forall (m :: * -> *) r. ReaderT (Env m) m r -> SafeT m r
    SafeT ReaderT (Env m) m (Env m)
    forall (m :: * -> *) r. Monad m => ReaderT r m r
    R.ask
            IO ReleaseKey -> SafeT m ReleaseKey
    forall a. IO a -> SafeT m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO ReleaseKey -> SafeT m ReleaseKey)
    -> IO ReleaseKey -> SafeT m ReleaseKey
    forall a b. (a -> b) -> a -> b
    $ do
                Integer
    n <- IORef (Maybe (Finalizers m))
    -> (Maybe (Finalizers m) -> (Maybe (Finalizers m), Integer))
    -> IO Integer
    forall a b. IORef a -> (a -> (a, b)) -> IO b
    atomicModifyIORef' IORef (Maybe (Finalizers m))
    ioref ((Maybe (Finalizers m) -> (Maybe (Finalizers m), Integer))
     -> IO Integer)
    -> (Maybe (Finalizers m) -> (Maybe (Finalizers m), Integer))
    -> IO Integer
    forall a b. (a -> b) -> a -> b
    $ \Maybe (Finalizers m)
    val ->
                    case Maybe (Finalizers m)
    val of
                        Maybe (Finalizers m)
    Nothing -> String -> (Maybe (Finalizers m), Integer)
    forall a. HasCallStack => String -> a
    error String
    "register: SafeT block is closed"
                        Just (Finalizers Integer
    n Map Integer (m ())
    fs) ->
                            (Finalizers m -> Maybe (Finalizers m)
    forall a. a -> Maybe a
    Just (Finalizers m -> Maybe (Finalizers m))
    -> Finalizers m -> Maybe (Finalizers m)
    forall a b. (a -> b) -> a -> b
    $! Integer -> Map Integer (m ()) -> Finalizers m
    forall (m :: * -> *). Integer -> Map Integer (m ()) -> Finalizers m
    Finalizers (Integer
    n Integer -> Integer -> Integer
    forall a. Num a => a -> a -> a
    + Integer
    1) (Integer -> m () -> Map Integer (m ()) -> Map Integer (m ())
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert Integer
    n m ()
    Base (SafeT m) ()
    io Map Integer (m ())
    fs), Integer
    n)
                ReleaseKey -> IO ReleaseKey
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Integer -> ReleaseKey
    ReleaseKey Integer
    n)

        release :: ReleaseKey -> SafeT m ()
    release ReleaseKey
    key = do
            Env IORef (Maybe (Finalizers m))
    ioref <- ReaderT (Env m) m (Env m) -> SafeT m (Env m)
    forall (m :: * -> *) r. ReaderT (Env m) m r -> SafeT m r
    SafeT ReaderT (Env m) m (Env m)
    forall (m :: * -> *) r. Monad m => ReaderT r m r
    R.ask
            IO () -> SafeT m ()
    forall a. IO a -> SafeT m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> SafeT m ()) -> IO () -> SafeT m ()
    forall a b. (a -> b) -> a -> b
    $ IORef (Maybe (Finalizers m))
    -> (Maybe (Finalizers m) -> (Maybe (Finalizers m), ())) -> IO ()
    forall a b. IORef a -> (a -> (a, b)) -> IO b
    atomicModifyIORef' IORef (Maybe (Finalizers m))
    ioref ((Maybe (Finalizers m) -> (Maybe (Finalizers m), ())) -> IO ())
    -> (Maybe (Finalizers m) -> (Maybe (Finalizers m), ())) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Maybe (Finalizers m)
    val ->
                case Maybe (Finalizers m)
    val of
                    Maybe (Finalizers m)
    Nothing -> String -> (Maybe (Finalizers m), ())
    forall a. HasCallStack => String -> a
    error String
    "release: SafeT block is closed"
                    Just (Finalizers Integer
    n Map Integer (m ())
    fs) ->
                        (Finalizers m -> Maybe (Finalizers m)
    forall a. a -> Maybe a
    Just (Finalizers m -> Maybe (Finalizers m))
    -> Finalizers m -> Maybe (Finalizers m)
    forall a b. (a -> b) -> a -> b
    $! Integer -> Map Integer (m ()) -> Finalizers m
    forall (m :: * -> *). Integer -> Map Integer (m ()) -> Finalizers m
    Finalizers Integer
    n (Integer -> Map Integer (m ()) -> Map Integer (m ())
    forall k a. Ord k => k -> Map k a -> Map k a
    M.delete (ReleaseKey -> Integer
    unlock ReleaseKey
    key) Map Integer (m ())
    fs), ())

    instance MonadSafe m => MonadSafe (Proxy a' a b' b m) where
        type Base (Proxy a' a b' b m) = Base m
        liftBase :: forall r. Base (Proxy a' a b' b m) r -> Proxy a' a b' b m r
    liftBase = m r -> Proxy a' a b' b m r
    forall (m :: * -> *) a. Monad m => m a -> Proxy a' a b' b m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> Proxy a' a b' b m r)
    -> (Base m r -> m r) -> Base m r -> Proxy a' a b' b m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (Proxy a' a b' b m) () -> Proxy a' a b' b m ReleaseKey
    register = m ReleaseKey -> Proxy a' a b' b m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> Proxy a' a b' b m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> Proxy a' a b' b m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> Proxy a' a b' b m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> Proxy a' a b' b m ()
    release  = m () -> Proxy a' a b' b m ()
    forall (m :: * -> *) a. Monad m => m a -> Proxy a' a b' b m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> Proxy a' a b' b m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> Proxy a' a b' b m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m) => MonadSafe (I.IdentityT m) where
        type Base (I.IdentityT m) = Base m
        liftBase :: forall r. Base (IdentityT m) r -> IdentityT m r
    liftBase = m r -> IdentityT m r
    forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> IdentityT m r)
    -> (Base m r -> m r) -> Base m r -> IdentityT m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (IdentityT m) () -> IdentityT m ReleaseKey
    register = m ReleaseKey -> IdentityT m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> IdentityT m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> IdentityT m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> IdentityT m ()
    release  = m () -> IdentityT m ()
    forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> IdentityT m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> IdentityT m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m) => MonadSafe (E.CatchT m) where
        type Base (E.CatchT m) = Base m
        liftBase :: forall r. Base (CatchT m) r -> CatchT m r
    liftBase = m r -> CatchT m r
    forall (m :: * -> *) a. Monad m => m a -> CatchT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> CatchT m r) -> (Base m r -> m r) -> Base m r -> CatchT m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (CatchT m) () -> CatchT m ReleaseKey
    register = m ReleaseKey -> CatchT m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> CatchT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> CatchT m ReleaseKey)
    -> (Base m () -> m ReleaseKey) -> Base m () -> CatchT m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> CatchT m ()
    release  = m () -> CatchT m ()
    forall (m :: * -> *) a. Monad m => m a -> CatchT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> CatchT m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> CatchT m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m) => MonadSafe (R.ReaderT i m) where
        type Base (R.ReaderT i m) = Base m
        liftBase :: forall r. Base (ReaderT i m) r -> ReaderT i m r
    liftBase = m r -> ReaderT i m r
    forall (m :: * -> *) a. Monad m => m a -> ReaderT i m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> ReaderT i m r)
    -> (Base m r -> m r) -> Base m r -> ReaderT i m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (ReaderT i m) () -> ReaderT i m ReleaseKey
    register = m ReleaseKey -> ReaderT i m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> ReaderT i m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> ReaderT i m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> ReaderT i m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> ReaderT i m ()
    release  = m () -> ReaderT i m ()
    forall (m :: * -> *) a. Monad m => m a -> ReaderT i m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> ReaderT i m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> ReaderT i m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m) => MonadSafe (S.StateT s m) where
        type Base (S.StateT s m) = Base m
        liftBase :: forall r. Base (StateT s m) r -> StateT s m r
    liftBase = m r -> StateT s m r
    forall (m :: * -> *) a. Monad m => m a -> StateT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> StateT s m r)
    -> (Base m r -> m r) -> Base m r -> StateT s m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (StateT s m) () -> StateT s m ReleaseKey
    register = m ReleaseKey -> StateT s m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> StateT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> StateT s m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> StateT s m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> StateT s m ()
    release  = m () -> StateT s m ()
    forall (m :: * -> *) a. Monad m => m a -> StateT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> StateT s m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> StateT s m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m) => MonadSafe (S'.StateT s m) where
        type Base (S'.StateT s m) = Base m
        liftBase :: forall r. Base (StateT s m) r -> StateT s m r
    liftBase = m r -> StateT s m r
    forall (m :: * -> *) a. Monad m => m a -> StateT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> StateT s m r)
    -> (Base m r -> m r) -> Base m r -> StateT s m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (StateT s m) () -> StateT s m ReleaseKey
    register = m ReleaseKey -> StateT s m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> StateT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> StateT s m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> StateT s m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> StateT s m ()
    release  = m () -> StateT s m ()
    forall (m :: * -> *) a. Monad m => m a -> StateT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> StateT s m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> StateT s m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m, Monoid w) => MonadSafe (W.WriterT w m) where
        type Base (W.WriterT w m) = Base m
        liftBase :: forall r. Base (WriterT w m) r -> WriterT w m r
    liftBase = m r -> WriterT w m r
    forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> WriterT w m r)
    -> (Base m r -> m r) -> Base m r -> WriterT w m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (WriterT w m) () -> WriterT w m ReleaseKey
    register = m ReleaseKey -> WriterT w m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> WriterT w m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> WriterT w m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> WriterT w m ()
    release  = m () -> WriterT w m ()
    forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> WriterT w m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> WriterT w m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m, Monoid w) => MonadSafe (W'.WriterT w m) where
        type Base (W'.WriterT w m) = Base m
        liftBase :: forall r. Base (WriterT w m) r -> WriterT w m r
    liftBase = m r -> WriterT w m r
    forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> WriterT w m r)
    -> (Base m r -> m r) -> Base m r -> WriterT w m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (WriterT w m) () -> WriterT w m ReleaseKey
    register = m ReleaseKey -> WriterT w m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> WriterT w m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> WriterT w m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> WriterT w m ()
    release  = m () -> WriterT w m ()
    forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> WriterT w m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> WriterT w m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m, Monoid w) => MonadSafe (RWS.RWST i w s m) where
        type Base (RWS.RWST i w s m) = Base m
        liftBase :: forall r. Base (RWST i w s m) r -> RWST i w s m r
    liftBase = m r -> RWST i w s m r
    forall (m :: * -> *) a. Monad m => m a -> RWST i w s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> RWST i w s m r)
    -> (Base m r -> m r) -> Base m r -> RWST i w s m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (RWST i w s m) () -> RWST i w s m ReleaseKey
    register = m ReleaseKey -> RWST i w s m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> RWST i w s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> RWST i w s m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> RWST i w s m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> RWST i w s m ()
    release  = m () -> RWST i w s m ()
    forall (m :: * -> *) a. Monad m => m a -> RWST i w s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> RWST i w s m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> RWST i w s m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    instance (MonadSafe m, Monoid w) => MonadSafe (RWS'.RWST i w s m) where
        type Base (RWS'.RWST i w s m) = Base m
        liftBase :: forall r. Base (RWST i w s m) r -> RWST i w s m r
    liftBase = m r -> RWST i w s m r
    forall (m :: * -> *) a. Monad m => m a -> RWST i w s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m r -> RWST i w s m r)
    -> (Base m r -> m r) -> Base m r -> RWST i w s m r
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m r -> m r
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase
        register :: Base (RWST i w s m) () -> RWST i w s m ReleaseKey
    register = m ReleaseKey -> RWST i w s m ReleaseKey
    forall (m :: * -> *) a. Monad m => m a -> RWST i w s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m ReleaseKey -> RWST i w s m ReleaseKey)
    -> (Base m () -> m ReleaseKey)
    -> Base m ()
    -> RWST i w s m ReleaseKey
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register
        release :: ReleaseKey -> RWST i w s m ()
    release  = m () -> RWST i w s m ()
    forall (m :: * -> *) a. Monad m => m a -> RWST i w s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> RWST i w s m ())
    -> (ReleaseKey -> m ()) -> ReleaseKey -> RWST i w s m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release

    {-| Analogous to 'C.onException' from @Control.Monad.Catch@, except this also
        protects against premature termination

        @(\`onException\` io)@ is a monad morphism.
    -}
    onException :: (MonadSafe m) => m a -> Base m b -> m a
    m a
    m1 onException :: forall (m :: * -> *) a b. MonadSafe m => m a -> Base m b -> m a
    `onException` Base m b
    io = do
        ReleaseKey
    key <- Base m () -> m ReleaseKey
    forall (m :: * -> *). MonadSafe m => Base m () -> m ReleaseKey
    register (Base m b
    io Base m b -> Base m () -> Base m ()
    forall a b. Base m a -> Base m b -> Base m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> () -> Base m ()
    forall a. a -> Base m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ())
        a
    r   <- m a
    m1
        ReleaseKey -> m ()
    forall (m :: * -> *). MonadSafe m => ReleaseKey -> m ()
    release ReleaseKey
    key
        a -> m a
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    r
    {-# INLINABLE onException #-}

    {- $utilities
        These utilities let you supply a finalizer that runs in the 'Base' monad
        (i.e. the monad directly beneath 'SafeT').  If you don't need to use the
        full power of the 'Base' monad and you only need to use to use 'IO', then
        just wrap the finalizer in 'liftIO', like this:

    > myAction `finally` (liftIO myFinalizer)

        This will lead to a simple inferred type with a single 'MonadSafe'
        constraint:

    > (MonadSafe m) => ...

        For examples of this, see the utilities in "Pipes.Safe.Prelude".

        If you omit the 'liftIO', the compiler will infer the following constraint
        instead:

    > (MonadSafe m, Base m ~ IO) => ...

        This means that this function would require 'IO' directly beneath the
        'SafeT' monad transformer, which might not be what you want.
    -}

    {-| Analogous to 'C.finally' from @Control.Monad.Catch@, except this also
        protects against premature termination
    -}
    finally :: (MonadSafe m) => m a -> Base m b -> m a
    m a
    m1 finally :: forall (m :: * -> *) a b. MonadSafe m => m a -> Base m b -> m a
    `finally` Base m b
    after = Base m () -> Base m b -> m a -> m a
    forall (m :: * -> *) a b c.
    MonadSafe m =>
    Base m a -> Base m b -> m c -> m c
    bracket_ (() -> Base m ()
    forall a. a -> Base m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()) Base m b
    after m a
    m1
    {-# INLINABLE finally #-}

    {-| Analogous to 'C.bracket' from @Control.Monad.Catch@, except this also
        protects against premature termination
    -}
    bracket :: (MonadSafe m) => Base m a -> (a -> Base m b) -> (a -> m c) -> m c
    bracket :: forall (m :: * -> *) a b c.
    MonadSafe m =>
    Base m a -> (a -> Base m b) -> (a -> m c) -> m c
    bracket Base m a
    before a -> Base m b
    after a -> m c
    action = ((forall a. m a -> m a) -> m c) -> m c
    forall b. HasCallStack => ((forall a. m a -> m a) -> m b) -> m b
    forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. m a -> m a) -> m b) -> m b
    mask (((forall a. m a -> m a) -> m c) -> m c)
    -> ((forall a. m a -> m a) -> m c) -> m c
    forall a b. (a -> b) -> a -> b
    $ \forall a. m a -> m a
    restore -> do
        a
    h <- Base m a -> m a
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase Base m a
    before
        c
    r <- m c -> m c
    forall a. m a -> m a
    restore (a -> m c
    action a
    h) m c -> Base m b -> m c
    forall (m :: * -> *) a b. MonadSafe m => m a -> Base m b -> m a
    `onException` a -> Base m b
    after a
    h
        b
    _ <- Base m b -> m b
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase (a -> Base m b
    after a
    h)
        c -> m c
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return c
    r
    {-# INLINABLE bracket #-}

    {-| Analogous to 'C.bracket_' from @Control.Monad.Catch@, except this also
        protects against premature termination
    -}
    bracket_ :: (MonadSafe m) => Base m a -> Base m b -> m c -> m c
    bracket_ :: forall (m :: * -> *) a b c.
    MonadSafe m =>
    Base m a -> Base m b -> m c -> m c
    bracket_ Base m a
    before Base m b
    after m c
    action = Base m a -> (a -> Base m b) -> (a -> m c) -> m c
    forall (m :: * -> *) a b c.
    MonadSafe m =>
    Base m a -> (a -> Base m b) -> (a -> m c) -> m c
    bracket Base m a
    before (\a
    _ -> Base m b
    after) (\a
    _ -> m c
    action)
    {-# INLINABLE bracket_ #-}

    {-| Analogous to 'C.bracketOnError' from @Control.Monad.Catch@, except this also
        protects against premature termination
    -}
    bracketOnError
        :: (MonadSafe m) => Base m a -> (a -> Base m b) -> (a -> m c) -> m c
    bracketOnError :: forall (m :: * -> *) a b c.
    MonadSafe m =>
    Base m a -> (a -> Base m b) -> (a -> m c) -> m c
    bracketOnError Base m a
    before a -> Base m b
    after a -> m c
    action = ((forall a. m a -> m a) -> m c) -> m c
    forall b. HasCallStack => ((forall a. m a -> m a) -> m b) -> m b
    forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. m a -> m a) -> m b) -> m b
    mask (((forall a. m a -> m a) -> m c) -> m c)
    -> ((forall a. m a -> m a) -> m c) -> m c
    forall a b. (a -> b) -> a -> b
    $ \forall a. m a -> m a
    restore -> do
        a
    h <- Base m a -> m a
    forall r. Base m r -> m r
    forall (m :: * -> *) r. MonadSafe m => Base m r -> m r
    liftBase Base m a
    before
        m c -> m c
    forall a. m a -> m a
    restore (a -> m c
    action a
    h) m c -> Base m b -> m c
    forall (m :: * -> *) a b. MonadSafe m => m a -> Base m b -> m a
    `onException` a -> Base m b
    after a
    h
    {-# INLINABLE bracketOnError #-}

    {- $reexports
        @Control.Monad.Catch@ re-exports all functions except for the ones that
        conflict with the generalized versions provided here (i.e. 'bracket',
        'finally', etc.).

        @Control.Exception@ re-exports 'Exception' and 'SomeException'.
    -}

    {- | Transform a 'Proxy' into one that catches any exceptions caused by its
         effects, and returns the resulting exception.
    -}
    tryP :: (MonadSafe m, Exception e)
         => Proxy a' a b' b m r -> Proxy a' a b' b m (Either e r)
    tryP :: forall (m :: * -> *) e a' a b' b r.
    (MonadSafe m, Exception e) =>
    Proxy a' a b' b m r -> Proxy a' a b' b m (Either e r)
    tryP Proxy a' a b' b m r
    p = case Proxy a' a b' b m r
    p of
        Request  a'
    a' a -> Proxy a' a b' b m r
    fa  -> a'
    -> (a -> Proxy a' a b' b m (Either e r))
    -> Proxy a' a b' b m (Either e r)
    forall a' a b' b (m :: * -> *) r.
    a' -> (a -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    Request a'
    a' (\a
    a  -> Proxy a' a b' b m r -> Proxy a' a b' b m (Either e r)
    forall (m :: * -> *) e a' a b' b r.
    (MonadSafe m, Exception e) =>
    Proxy a' a b' b m r -> Proxy a' a b' b m (Either e r)
    tryP (a -> Proxy a' a b' b m r
    fa  a
    a))
        Respond  b
    b  b' -> Proxy a' a b' b m r
    fb' -> b
    -> (b' -> Proxy a' a b' b m (Either e r))
    -> Proxy a' a b' b m (Either e r)
    forall a' a b' b (m :: * -> *) r.
    b -> (b' -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    Respond b
    b  (\b'
    b' -> Proxy a' a b' b m r -> Proxy a' a b' b m (Either e r)
    forall (m :: * -> *) e a' a b' b r.
    (MonadSafe m, Exception e) =>
    Proxy a' a b' b m r -> Proxy a' a b' b m (Either e r)
    tryP (b' -> Proxy a' a b' b m r
    fb' b'
    b'))
        M        m (Proxy a' a b' b m r)
    m      -> m (Proxy a' a b' b m (Either e r))
    -> Proxy a' a b' b m (Either e r)
    forall a' a b' b (m :: * -> *) r.
    m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
    M (m (Proxy a' a b' b m (Either e r))
     -> Proxy a' a b' b m (Either e r))
    -> m (Proxy a' a b' b m (Either e r))
    -> Proxy a' a b' b m (Either e r)
    forall a b. (a -> b) -> a -> b
    $ m (Proxy a' a b' b m r) -> m (Either e (Proxy a' a b' b m r))
    forall (m :: * -> *) e a.
    (HasCallStack, MonadCatch m, Exception e) =>
    m a -> m (Either e a)
    C.try m (Proxy a' a b' b m r)
    m m (Either e (Proxy a' a b' b m r))
    -> (Either e (Proxy a' a b' b m r)
        -> m (Proxy a' a b' b m (Either e r)))
    -> m (Proxy a' a b' b m (Either e r))
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \Either e (Proxy a' a b' b m r)
    eres -> Proxy a' a b' b m (Either e r)
    -> m (Proxy a' a b' b m (Either e r))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Proxy a' a b' b m (Either e r)
     -> m (Proxy a' a b' b m (Either e r)))
    -> Proxy a' a b' b m (Either e r)
    -> m (Proxy a' a b' b m (Either e r))
    forall a b. (a -> b) -> a -> b
    $ case Either e (Proxy a' a b' b m r)
    eres of
            Left  e
    e -> Either e r -> Proxy a' a b' b m (Either e r)
    forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
    Pure (e -> Either e r
    forall a b. a -> Either a b
    Left e
    e)
            Right Proxy a' a b' b m r
    a -> Proxy a' a b' b m r -> Proxy a' a b' b m (Either e r)
    forall (m :: * -> *) e a' a b' b r.
    (MonadSafe m, Exception e) =>
    Proxy a' a b' b m r -> Proxy a' a b' b m (Either e r)
    tryP Proxy a' a b' b m r
    a
        Pure     r
    r      -> Either e r -> Proxy a' a b' b m (Either e r)
    forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
    Pure (r -> Either e r
    forall a b. b -> Either a b
    Right r
    r)

    {- | Allows direct handling of exceptions raised by the effects in a 'Proxy'.
    -}
    catchP :: (MonadSafe m, Exception e)
           => Proxy a' a b' b m r -> (e -> Proxy a' a b' b m r)
           -> Proxy a' a b' b m r
    catchP :: forall (m :: * -> *) e a' a b' b r.
    (MonadSafe m, Exception e) =>
    Proxy a' a b' b m r
    -> (e -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    catchP Proxy a' a b' b m r
    p0 e -> Proxy a' a b' b m r
    f = Proxy a' a b' b m r -> Proxy a' a b' b m r
    go Proxy a' a b' b m r
    p0
      where
        go :: Proxy a' a b' b m r -> Proxy a' a b' b m r
    go Proxy a' a b' b m r
    p = case Proxy a' a b' b m r
    p of
            Request  a'
    a' a -> Proxy a' a b' b m r
    fa  -> a' -> (a -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    forall a' a b' b (m :: * -> *) r.
    a' -> (a -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    Request a'
    a' (\a
    a  -> Proxy a' a b' b m r -> Proxy a' a b' b m r
    go (a -> Proxy a' a b' b m r
    fa  a
    a))
            Respond  b
    b  b' -> Proxy a' a b' b m r
    fb' -> b -> (b' -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    forall a' a b' b (m :: * -> *) r.
    b -> (b' -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
    Respond b
    b  (\b'
    b' -> Proxy a' a b' b m r -> Proxy a' a b' b m r
    go (b' -> Proxy a' a b' b m r
    fb' b'
    b'))
            M        m (Proxy a' a b' b m r)
    m      -> m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
    forall a' a b' b (m :: * -> *) r.
    m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
    M (m (Proxy a' a b' b m r) -> Proxy a' a b' b m r)
    -> m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
    forall a b. (a -> b) -> a -> b
    $ m (Proxy a' a b' b m r)
    -> (e -> m (Proxy a' a b' b m r)) -> m (Proxy a' a b' b m r)
    forall e a. (HasCallStack, Exception e) => m a -> (e -> m a) -> m a
    forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    m a -> (e -> m a) -> m a
    C.catch ((Proxy a' a b' b m r -> Proxy a' a b' b m r)
    -> m (Proxy a' a b' b m r) -> m (Proxy a' a b' b m r)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM Proxy a' a b' b m r -> Proxy a' a b' b m r
    go m (Proxy a' a b' b m r)
    m) (Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Proxy a' a b' b m r -> m (Proxy a' a b' b m r))
    -> (e -> Proxy a' a b' b m r) -> e -> m (Proxy a' a b' b m r)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . e -> Proxy a' a b' b m r
    f)
            Pure     r
    r      -> r -> Proxy a' a b' b m r
    forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
    Pure r
    r