{-# LANGUAGE DeriveFunctor, ExistentialQuantification, RankNTypes, StandaloneDeriving #-}
-- | Operations from "Control.Exception" lifted into effectful contexts using 'Control.Effect.Lift.Lift'.
--
-- @since 1.0.0.0
module Control.Effect.Exception
( -- * Lifted "Control.Exception" operations
  throwIO
, ioError
, throwTo
, catch
, catches
, Handler(..)
, catchJust
, handle
, handleJust
, try
, tryJust
, evaluate
, mask
, mask_
, uninterruptibleMask
, uninterruptibleMask_
, getMaskingState
, interruptible
, allowInterrupt
, bracket
, bracket_
, bracketOnError
, finally
, onException
, module Control.Exception
  -- * Lift effect
, Lift(..)
, sendM
, liftWith
  -- * Re-exports
, Algebra
, Has
, run
) where

import Control.Concurrent (ThreadId)
import Control.Effect.Lift
import Control.Exception hiding
  ( throwIO
  , ioError
  , throwTo
  , catch
  , catches
  , Handler
  , catchJust
  , handle
  , handleJust
  , try
  , tryJust
  , evaluate
  , mask
  , mask_
  , uninterruptibleMask
  , uninterruptibleMask_
  , getMaskingState
  , interruptible
  , allowInterrupt
  , bracket
  , bracket_
  , bracketOnError
  , finally
  , onException
  )
import qualified Control.Exception as Exc
import Prelude hiding (ioError)

-- | See @"Control.Exception".'Exc.throwIO'@.
--
-- @since 1.0.0.0
throwIO :: (Exc.Exception e, Has (Lift IO) sig m) => e -> m a
throwIO :: forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Exception e, Has (Lift IO) sig m) =>
e -> m a
throwIO = IO a -> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Has (Lift n) sig m, Functor n) =>
n a -> m a
sendM (IO a -> m a) -> (e -> IO a) -> e -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> IO a
forall e a. Exception e => e -> IO a
Exc.throwIO

-- | See @"Control.Exception".'Exc.ioError'@.
--
-- @since 1.0.0.0
ioError :: Has (Lift IO) sig m => IOError -> m a
ioError :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift IO) sig m =>
IOError -> m a
ioError = IO a -> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Has (Lift n) sig m, Functor n) =>
n a -> m a
sendM (IO a -> m a) -> (IOError -> IO a) -> IOError -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IO a
forall a. IOError -> IO a
Exc.ioError

-- | See @"Control.Exception".'Exc.throwTo'@.
--
-- @since 1.0.0.0
throwTo :: (Exc.Exception e, Has (Lift IO) sig m) => ThreadId -> e -> m ()
throwTo :: forall e (sig :: (* -> *) -> * -> *) (m :: * -> *).
(Exception e, Has (Lift IO) sig m) =>
ThreadId -> e -> m ()
throwTo ThreadId
thread = IO () -> m ()
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Has (Lift n) sig m, Functor n) =>
n a -> m a
sendM (IO () -> m ()) -> (e -> IO ()) -> e -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThreadId -> e -> IO ()
forall e. Exception e => ThreadId -> e -> IO ()
Exc.throwTo ThreadId
thread

-- | See @"Control.Exception".'Exc.catch'@.
--
-- @since 1.0.0.0
catch :: (Exc.Exception e, Has (Lift IO) sig m) => m a -> (e -> m a) -> m a
catch :: forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Exception e, Has (Lift IO) sig m) =>
m a -> (e -> m a) -> m a
catch m a
m e -> m a
h = (forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift n) sig m =>
(forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m n -> ctx () -> n (ctx a))
-> m a
liftWith ((forall (ctx :: * -> *).
  Functor ctx =>
  Handler ctx m IO -> ctx () -> IO (ctx a))
 -> m a)
-> (forall (ctx :: * -> *).
    Functor ctx =>
    Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall a b. (a -> b) -> a -> b
$ \ Handler ctx m IO
run ctx ()
ctx -> ctx (m a) -> IO (ctx a)
Handler ctx m IO
run (m a
m m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx) IO (ctx a) -> (e -> IO (ctx a)) -> IO (ctx a)
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`Exc.catch` (ctx (m a) -> IO (ctx a)
Handler ctx m IO
run (ctx (m a) -> IO (ctx a)) -> (e -> ctx (m a)) -> e -> IO (ctx a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx) (m a -> ctx (m a)) -> (e -> m a) -> e -> ctx (m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
h)

-- | See @"Control.Exception".'Exc.catches'@.
--
-- @since 1.0.0.0
catches :: Has (Lift IO) sig m => m a -> [Handler m a] -> m a
catches :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift IO) sig m =>
m a -> [Handler m a] -> m a
catches m a
m [Handler m a]
hs = (forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift n) sig m =>
(forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m n -> ctx () -> n (ctx a))
-> m a
liftWith ((forall (ctx :: * -> *).
  Functor ctx =>
  Handler ctx m IO -> ctx () -> IO (ctx a))
 -> m a)
-> (forall (ctx :: * -> *).
    Functor ctx =>
    Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall a b. (a -> b) -> a -> b
$ \ Handler ctx m IO
run ctx ()
ctx ->
  IO (ctx a) -> [Handler (ctx a)] -> IO (ctx a)
forall a. IO a -> [Handler a] -> IO a
Exc.catches (ctx (m a) -> IO (ctx a)
Handler ctx m IO
run (m a
m m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx)) ((Handler m a -> Handler (ctx a))
-> [Handler m a] -> [Handler (ctx a)]
forall a b. (a -> b) -> [a] -> [b]
map (\ (Handler e -> m a
h) -> (e -> IO (ctx a)) -> Handler (ctx a)
forall a e. Exception e => (e -> IO a) -> Handler a
Exc.Handler (ctx (m a) -> IO (ctx a)
Handler ctx m IO
run (ctx (m a) -> IO (ctx a)) -> (e -> ctx (m a)) -> e -> IO (ctx a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx) (m a -> ctx (m a)) -> (e -> m a) -> e -> ctx (m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
h)) [Handler m a]
hs)

-- | See @"Control.Exception".'Exc.Handler'@.
--
-- @since 1.0.0.0
data Handler m a
  = forall e . Exc.Exception e => Handler (e -> m a)

deriving instance Functor m => Functor (Handler m)

-- | See @"Control.Exception".'Exc.catchJust'@.
--
-- @since 1.0.0.0
catchJust
  :: (Exc.Exception e, Has (Lift IO) sig m)
  => (e -> Maybe b)
  -> m a
  -> (b -> m a)
  -> m a
catchJust :: forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) b a.
(Exception e, Has (Lift IO) sig m) =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust e -> Maybe b
p m a
m b -> m a
h = (forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift n) sig m =>
(forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m n -> ctx () -> n (ctx a))
-> m a
liftWith ((forall (ctx :: * -> *).
  Functor ctx =>
  Handler ctx m IO -> ctx () -> IO (ctx a))
 -> m a)
-> (forall (ctx :: * -> *).
    Functor ctx =>
    Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall a b. (a -> b) -> a -> b
$ \ Handler ctx m IO
run ctx ()
ctx -> (e -> Maybe b) -> IO (ctx a) -> (b -> IO (ctx a)) -> IO (ctx a)
forall e b a.
Exception e =>
(e -> Maybe b) -> IO a -> (b -> IO a) -> IO a
Exc.catchJust e -> Maybe b
p (ctx (m a) -> IO (ctx a)
Handler ctx m IO
run (m a
m m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx)) (ctx (m a) -> IO (ctx a)
Handler ctx m IO
run (ctx (m a) -> IO (ctx a)) -> (b -> ctx (m a)) -> b -> IO (ctx a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx) (m a -> ctx (m a)) -> (b -> m a) -> b -> ctx (m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> m a
h)

-- | See @"Control.Exception".'Exc.handle'@.
--
-- @since 1.0.0.0
handle :: (Exc.Exception e, Has (Lift IO) sig m) => (e -> m a) -> m a -> m a
handle :: forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Exception e, Has (Lift IO) sig m) =>
(e -> m a) -> m a -> m a
handle = (m a -> (e -> m a) -> m a) -> (e -> m a) -> m a -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip m a -> (e -> m a) -> m a
forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Exception e, Has (Lift IO) sig m) =>
m a -> (e -> m a) -> m a
catch

-- | See @"Control.Exception".'Exc.handleJust'@.
--
-- @since 1.0.0.0
handleJust
  :: (Exc.Exception e, Has (Lift IO) sig m)
  => (e -> Maybe b)
  -> (b -> m a)
  -> m a
  -> m a
handleJust :: forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) b a.
(Exception e, Has (Lift IO) sig m) =>
(e -> Maybe b) -> (b -> m a) -> m a -> m a
handleJust e -> Maybe b
p = (m a -> (b -> m a) -> m a) -> (b -> m a) -> m a -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((e -> Maybe b) -> m a -> (b -> m a) -> m a
forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) b a.
(Exception e, Has (Lift IO) sig m) =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust e -> Maybe b
p)

-- | See @"Control.Exception".'Exc.try'@.
--
-- @since 1.0.0.0
try :: (Exc.Exception e, Has (Lift IO) sig m) => m a -> m (Either e a)
try :: forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Exception e, Has (Lift IO) sig m) =>
m a -> m (Either e a)
try m a
m = (a -> Either e a
forall a b. b -> Either a b
Right (a -> Either e a) -> m a -> m (Either e a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
m) m (Either e a) -> (e -> m (Either e a)) -> m (Either e a)
forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Exception e, Has (Lift IO) sig m) =>
m a -> (e -> m a) -> m a
`catch` (Either e a -> m (Either e a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either e a -> m (Either e a))
-> (e -> Either e a) -> e -> m (Either e a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> Either e a
forall a b. a -> Either a b
Left)

-- | See @"Control.Exception".'Exc.tryJust'@.
--
-- @since 1.0.0.0
tryJust :: (Exc.Exception e, Has (Lift IO) sig m) => (e -> Maybe b) -> m a -> m (Either b a)
tryJust :: forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) b a.
(Exception e, Has (Lift IO) sig m) =>
(e -> Maybe b) -> m a -> m (Either b a)
tryJust e -> Maybe b
p m a
m = (e -> Maybe b)
-> m (Either b a) -> (b -> m (Either b a)) -> m (Either b a)
forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) b a.
(Exception e, Has (Lift IO) sig m) =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust e -> Maybe b
p (a -> Either b a
forall a b. b -> Either a b
Right (a -> Either b a) -> m a -> m (Either b a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
m) (Either b a -> m (Either b a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either b a -> m (Either b a))
-> (b -> Either b a) -> b -> m (Either b a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Either b a
forall a b. a -> Either a b
Left)

-- | See @"Control.Exception".'Exc.evaluate'@.
--
-- @since 1.0.0.0
evaluate :: Has (Lift IO) sig m => a -> m a
evaluate :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift IO) sig m =>
a -> m a
evaluate = IO a -> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Has (Lift n) sig m, Functor n) =>
n a -> m a
sendM (IO a -> m a) -> (a -> IO a) -> a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> IO a
forall a. a -> IO a
Exc.evaluate

-- | See @"Control.Exception".'Exc.mask'@.
--
-- @since 1.0.0.0
mask :: Has (Lift IO) sig m => ((forall a . m a -> m a) -> m b) -> m b
mask :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) b.
Has (Lift IO) sig m =>
((forall a. m a -> m a) -> m b) -> m b
mask (forall a. m a -> m a) -> m b
with = (forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m IO -> ctx () -> IO (ctx b))
-> m b
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift n) sig m =>
(forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m n -> ctx () -> n (ctx a))
-> m a
liftWith ((forall (ctx :: * -> *).
  Functor ctx =>
  Handler ctx m IO -> ctx () -> IO (ctx b))
 -> m b)
-> (forall (ctx :: * -> *).
    Functor ctx =>
    Handler ctx m IO -> ctx () -> IO (ctx b))
-> m b
forall a b. (a -> b) -> a -> b
$ \ Handler ctx m IO
run ctx ()
ctx -> ((forall a. IO a -> IO a) -> IO (ctx b)) -> IO (ctx b)
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
Exc.mask (((forall a. IO a -> IO a) -> IO (ctx b)) -> IO (ctx b))
-> ((forall a. IO a -> IO a) -> IO (ctx b)) -> IO (ctx b)
forall a b. (a -> b) -> a -> b
$ \ forall a. IO a -> IO a
restore ->
  ctx (m b) -> IO (ctx b)
Handler ctx m IO
run ((forall a. m a -> m a) -> m b
with (\ m a
m -> (forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift n) sig m =>
(forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m n -> ctx () -> n (ctx a))
-> m a
liftWith ((forall (ctx :: * -> *).
  Functor ctx =>
  Handler ctx m IO -> ctx () -> IO (ctx a))
 -> m a)
-> (forall (ctx :: * -> *).
    Functor ctx =>
    Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall a b. (a -> b) -> a -> b
$ \ Handler ctx m IO
run' ctx ()
ctx' -> IO (ctx a) -> IO (ctx a)
forall a. IO a -> IO a
restore (ctx (m a) -> IO (ctx a)
Handler ctx m IO
run' (m a
m m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx'))) m b -> ctx () -> ctx (m b)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx)

-- | See @"Control.Exception".'Exc.mask_'@.
--
-- @since 1.0.0.0
mask_ :: Has (Lift IO) sig m => m a -> m a
mask_ :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift IO) sig m =>
m a -> m a
mask_ m a
m = ((forall a. m a -> m a) -> m a) -> m a
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) b.
Has (Lift IO) sig m =>
((forall a. m a -> m a) -> m b) -> m b
mask (\forall a. m a -> m a
_ -> m a
m)

-- | See @"Control.Exception".'Exc.uninterruptibleMask'@.
--
-- @since 1.0.0.0
uninterruptibleMask :: Has (Lift IO) sig m => ((forall a . m a -> m a) -> m b) -> m b
uninterruptibleMask :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) b.
Has (Lift IO) sig m =>
((forall a. m a -> m a) -> m b) -> m b
uninterruptibleMask (forall a. m a -> m a) -> m b
with = (forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m IO -> ctx () -> IO (ctx b))
-> m b
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift n) sig m =>
(forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m n -> ctx () -> n (ctx a))
-> m a
liftWith ((forall (ctx :: * -> *).
  Functor ctx =>
  Handler ctx m IO -> ctx () -> IO (ctx b))
 -> m b)
-> (forall (ctx :: * -> *).
    Functor ctx =>
    Handler ctx m IO -> ctx () -> IO (ctx b))
-> m b
forall a b. (a -> b) -> a -> b
$ \ Handler ctx m IO
run ctx ()
ctx -> ((forall a. IO a -> IO a) -> IO (ctx b)) -> IO (ctx b)
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
Exc.uninterruptibleMask (((forall a. IO a -> IO a) -> IO (ctx b)) -> IO (ctx b))
-> ((forall a. IO a -> IO a) -> IO (ctx b)) -> IO (ctx b)
forall a b. (a -> b) -> a -> b
$ \ forall a. IO a -> IO a
restore ->
  ctx (m b) -> IO (ctx b)
Handler ctx m IO
run ((forall a. m a -> m a) -> m b
with (\ m a
m -> (forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift n) sig m =>
(forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m n -> ctx () -> n (ctx a))
-> m a
liftWith ((forall (ctx :: * -> *).
  Functor ctx =>
  Handler ctx m IO -> ctx () -> IO (ctx a))
 -> m a)
-> (forall (ctx :: * -> *).
    Functor ctx =>
    Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall a b. (a -> b) -> a -> b
$ \ Handler ctx m IO
run' ctx ()
ctx' -> IO (ctx a) -> IO (ctx a)
forall a. IO a -> IO a
restore (ctx (m a) -> IO (ctx a)
Handler ctx m IO
run' (m a
m m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx'))) m b -> ctx () -> ctx (m b)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx)

-- | See @"Control.Exception".'Exc.uninterruptibleMask_'@.
--
-- @since 1.0.0.0
uninterruptibleMask_ :: Has (Lift IO) sig m => m a -> m a
uninterruptibleMask_ :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift IO) sig m =>
m a -> m a
uninterruptibleMask_ m a
m = ((forall a. m a -> m a) -> m a) -> m a
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) b.
Has (Lift IO) sig m =>
((forall a. m a -> m a) -> m b) -> m b
uninterruptibleMask (\forall a. m a -> m a
_ -> m a
m)

-- | See @"Control.Exception".'Exc.getMaskingState'@.
--
-- @since 1.0.0.0
getMaskingState :: Has (Lift IO) sig m => m Exc.MaskingState
getMaskingState :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (Lift IO) sig m =>
m MaskingState
getMaskingState = IO MaskingState -> m MaskingState
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Has (Lift n) sig m, Functor n) =>
n a -> m a
sendM IO MaskingState
Exc.getMaskingState

-- | See @"Control.Exception".'Exc.interruptible'@.
--
-- @since 1.0.0.0
interruptible :: Has (Lift IO) sig m => m a -> m a
interruptible :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift IO) sig m =>
m a -> m a
interruptible m a
m = (forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Lift n) sig m =>
(forall (ctx :: * -> *).
 Functor ctx =>
 Handler ctx m n -> ctx () -> n (ctx a))
-> m a
liftWith ((forall (ctx :: * -> *).
  Functor ctx =>
  Handler ctx m IO -> ctx () -> IO (ctx a))
 -> m a)
-> (forall (ctx :: * -> *).
    Functor ctx =>
    Handler ctx m IO -> ctx () -> IO (ctx a))
-> m a
forall a b. (a -> b) -> a -> b
$ \ Handler ctx m IO
run ctx ()
ctx -> IO (ctx a) -> IO (ctx a)
forall a. IO a -> IO a
Exc.interruptible (ctx (m a) -> IO (ctx a)
Handler ctx m IO
run (m a
m m a -> ctx () -> ctx (m a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ctx ()
ctx))

-- | See @"Control.Exception".'Exc.allowInterrupt'@.
--
-- @since 1.0.0.0
allowInterrupt :: Has (Lift IO) sig m => m ()
allowInterrupt :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (Lift IO) sig m =>
m ()
allowInterrupt = IO () -> m ()
forall (n :: * -> *) (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Has (Lift n) sig m, Functor n) =>
n a -> m a
sendM IO ()
Exc.allowInterrupt

-- | See @"Control.Exception".'Exc.bracket'@.
--
-- @since 1.0.0.0
bracket
  :: Has (Lift IO) sig m
  => m a
  -> (a -> m b)
  -> (a -> m c)
  -> m c
bracket :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b c.
Has (Lift IO) sig m =>
m a -> (a -> m b) -> (a -> m c) -> m c
bracket m a
acquire a -> m b
release a -> m c
m = ((forall a. m a -> m a) -> m c) -> m c
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) b.
Has (Lift IO) sig m =>
((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
a <- m a
acquire
  c
r <- m c -> m c
forall a. m a -> m a
restore (a -> m c
m a
a) m c -> m b -> m c
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b.
Has (Lift IO) sig m =>
m a -> m b -> m a
`onException` a -> m b
release a
a
  c
r c -> m b -> m c
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ a -> m b
release a
a

-- | See @"Control.Exception".'Exc.bracket_'@.
--
-- @since 1.0.0.0
bracket_
  :: Has (Lift IO) sig m
  => m a
  -> m b
  -> m c
  -> m c
bracket_ :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b c.
Has (Lift IO) sig m =>
m a -> m b -> m c -> m c
bracket_ m a
before m b
after m c
thing = m a -> (a -> m b) -> (a -> m c) -> m c
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b c.
Has (Lift IO) sig m =>
m a -> (a -> m b) -> (a -> m c) -> m c
bracket m a
before (m b -> a -> m b
forall a b. a -> b -> a
const m b
after) (m c -> a -> m c
forall a b. a -> b -> a
const m c
thing)

-- | See @"Control.Exception".'Exc.bracketOnError'@.
--
-- @since 1.0.0.0
bracketOnError
  :: Has (Lift IO) sig m
  => m a
  -> (a -> m b)
  -> (a -> m c)
  -> m c
bracketOnError :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b c.
Has (Lift IO) sig m =>
m a -> (a -> m b) -> (a -> m c) -> m c
bracketOnError m a
acquire a -> m b
release a -> m c
m = ((forall a. m a -> m a) -> m c) -> m c
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) b.
Has (Lift IO) sig m =>
((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
a <- m a
acquire
  m c -> m c
forall a. m a -> m a
restore (a -> m c
m a
a) m c -> m b -> m c
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b.
Has (Lift IO) sig m =>
m a -> m b -> m a
`onException` a -> m b
release a
a

-- | See @"Control.Exception".'Exc.finally'@.
--
-- @since 1.0.0.0
finally
  :: Has (Lift IO) sig m
  => m a
  -> m b
  -> m a
finally :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b.
Has (Lift IO) sig m =>
m a -> m b -> m a
finally m a
m m b
sequel = ((forall a. m a -> m a) -> m a) -> m a
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) b.
Has (Lift IO) sig m =>
((forall a. m a -> m a) -> m b) -> m b
mask (((forall a. m a -> m a) -> m a) -> m a)
-> ((forall a. m a -> m a) -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ \ forall a. m a -> m a
restore -> (m a -> m a
forall a. m a -> m a
restore m a
m m a -> m b -> m a
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b.
Has (Lift IO) sig m =>
m a -> m b -> m a
`onException` m b
sequel) m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m b
sequel

-- | See @"Control.Exception".'Exc.onException'@.
--
-- @since 1.0.0.0
onException :: Has (Lift IO) sig m => m a -> m b -> m a
onException :: forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a b.
Has (Lift IO) sig m =>
m a -> m b -> m a
onException m a
io m b
what = m a
io m a -> (SomeException -> m a) -> m a
forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Exception e, Has (Lift IO) sig m) =>
m a -> (e -> m a) -> m a
`catch` \SomeException
e -> m b
what m b -> m a -> m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SomeException -> m a
forall e (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
(Exception e, Has (Lift IO) sig m) =>
e -> m a
throwIO (SomeException
e :: Exc.SomeException)