{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-simplifiable-class-constraints #-}
module Capability.Error
(
HasThrow(..)
, throw
, HasCatch(..)
, catch
, catchJust
, wrapError
, HasThrow'
, HasCatch'
, TypeOf
, MonadError(..)
, MonadThrow(..)
, MonadCatch(..)
, SafeExceptions(..)
, MonadUnliftIO(..)
, module Capability.Accessors
, Reified(..)
, Exception(..)
, Typeable
) where
import Capability.Accessors
import Capability.Constraints
import Capability.Derive (derive)
import Capability.Reflection
import Capability.TypeOf
import Control.Exception (Exception(..))
import qualified Control.Exception.Safe as Safe
import Control.Lens (preview, review)
import Control.Monad ((<=<))
import qualified Control.Monad.Catch as Catch
import qualified Control.Monad.Except as Except
import Control.Monad.IO.Class (MonadIO)
import qualified Control.Monad.IO.Unlift as UnliftIO
import Control.Monad.Primitive (PrimMonad)
import Control.Monad.Trans.Class (MonadTrans, lift)
import Control.Monad.Trans.Control (MonadTransControl(..))
import Data.Coerce (Coercible, coerce)
import qualified Data.Generics.Sum.Constructors as Generic
import Data.Kind (Type)
import Data.Typeable (Typeable)
import GHC.Exts (Proxy#, proxy#)
import qualified UnliftIO.Exception as UnliftIO
class Monad m
=> HasThrow (tag :: k) (e :: Type) (m :: Type -> Type) | tag m -> e
where
throw_ :: Proxy# tag -> e -> m a
throw :: forall tag e m a. HasThrow tag e m => e -> m a
throw :: e -> m a
throw = Proxy# tag -> e -> m a
forall k (tag :: k) e (m :: * -> *) a.
HasThrow tag e m =>
Proxy# tag -> e -> m a
throw_ (Proxy# tag
forall k (a :: k). Proxy# a
proxy# @tag)
{-# INLINE throw #-}
class HasThrow tag e m
=> HasCatch (tag :: k) (e :: Type) (m :: Type -> Type) | tag m -> e
where
catch_ :: Proxy# tag -> m a -> (e -> m a) -> m a
catchJust_ :: Proxy# tag -> (e -> Maybe b) -> m a -> (b -> m a) -> m a
catch :: forall tag e m a. HasCatch tag e m => m a -> (e -> m a) -> m a
catch :: m a -> (e -> m a) -> m a
catch = Proxy# tag -> m a -> (e -> m a) -> m a
forall k (tag :: k) e (m :: * -> *) a.
HasCatch tag e m =>
Proxy# tag -> m a -> (e -> m a) -> m a
catch_ (Proxy# tag
forall k (a :: k). Proxy# a
proxy# @tag)
{-# INLINE catch #-}
catchJust :: forall tag e m a b. HasCatch tag e m
=> (e -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust :: (e -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust = Proxy# tag -> (e -> Maybe b) -> m a -> (b -> m a) -> m a
forall k (tag :: k) e (m :: * -> *) b a.
HasCatch tag e m =>
Proxy# tag -> (e -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust_ (Proxy# tag
forall k (a :: k). Proxy# a
proxy# @tag)
{-# INLINE catchJust #-}
wrapError :: forall innertag t (cs :: [Capability]) inner m a.
( forall x. Coercible (t m x) (m x)
, HasCatch innertag inner (t m)
, All cs m)
=> (forall m'. All (HasCatch innertag inner ': cs) m' => m' a) -> m a
wrapError :: (forall (m' :: * -> *).
All (HasCatch innertag inner : cs) m' =>
m' a)
-> m a
wrapError =
forall (m :: * -> *) a.
(forall x. Coercible (t m x) (m x),
All '[HasCatch innertag inner] (t m), All cs m) =>
(forall (m' :: * -> *).
(All '[HasCatch innertag inner] m', All cs m') =>
m' a)
-> m a
forall (t :: (* -> *) -> * -> *)
(derived :: [(* -> *) -> Constraint])
(ambient :: [(* -> *) -> Constraint]) (m :: * -> *) a.
(forall x. Coercible (t m x) (m x), All derived (t m),
All ambient m) =>
(forall (m' :: * -> *). (All derived m', All ambient m') => m' a)
-> m a
derive @t @'[HasCatch innertag inner] @cs
{-# INLINE wrapError #-}
newtype MonadError m (a :: Type) = MonadError (m a)
deriving (a -> MonadError m b -> MonadError m a
(a -> b) -> MonadError m a -> MonadError m b
(forall a b. (a -> b) -> MonadError m a -> MonadError m b)
-> (forall a b. a -> MonadError m b -> MonadError m a)
-> Functor (MonadError m)
forall a b. a -> MonadError m b -> MonadError m a
forall a b. (a -> b) -> MonadError m a -> MonadError m b
forall (m :: * -> *) a b.
Functor m =>
a -> MonadError m b -> MonadError m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> MonadError m a -> MonadError m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MonadError m b -> MonadError m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> MonadError m b -> MonadError m a
fmap :: (a -> b) -> MonadError m a -> MonadError m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> MonadError m a -> MonadError m b
Functor, Functor (MonadError m)
a -> MonadError m a
Functor (MonadError m)
-> (forall a. a -> MonadError m a)
-> (forall a b.
MonadError m (a -> b) -> MonadError m a -> MonadError m b)
-> (forall a b c.
(a -> b -> c)
-> MonadError m a -> MonadError m b -> MonadError m c)
-> (forall a b. MonadError m a -> MonadError m b -> MonadError m b)
-> (forall a b. MonadError m a -> MonadError m b -> MonadError m a)
-> Applicative (MonadError m)
MonadError m a -> MonadError m b -> MonadError m b
MonadError m a -> MonadError m b -> MonadError m a
MonadError m (a -> b) -> MonadError m a -> MonadError m b
(a -> b -> c) -> MonadError m a -> MonadError m b -> MonadError m c
forall a. a -> MonadError m a
forall a b. MonadError m a -> MonadError m b -> MonadError m a
forall a b. MonadError m a -> MonadError m b -> MonadError m b
forall a b.
MonadError m (a -> b) -> MonadError m a -> MonadError m b
forall a b c.
(a -> b -> c) -> MonadError m a -> MonadError m b -> MonadError 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 (MonadError m)
forall (m :: * -> *) a. Applicative m => a -> MonadError m a
forall (m :: * -> *) a b.
Applicative m =>
MonadError m a -> MonadError m b -> MonadError m a
forall (m :: * -> *) a b.
Applicative m =>
MonadError m a -> MonadError m b -> MonadError m b
forall (m :: * -> *) a b.
Applicative m =>
MonadError m (a -> b) -> MonadError m a -> MonadError m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> MonadError m a -> MonadError m b -> MonadError m c
<* :: MonadError m a -> MonadError m b -> MonadError m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
MonadError m a -> MonadError m b -> MonadError m a
*> :: MonadError m a -> MonadError m b -> MonadError m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
MonadError m a -> MonadError m b -> MonadError m b
liftA2 :: (a -> b -> c) -> MonadError m a -> MonadError m b -> MonadError m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> MonadError m a -> MonadError m b -> MonadError m c
<*> :: MonadError m (a -> b) -> MonadError m a -> MonadError m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
MonadError m (a -> b) -> MonadError m a -> MonadError m b
pure :: a -> MonadError m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> MonadError m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (MonadError m)
Applicative, Applicative (MonadError m)
a -> MonadError m a
Applicative (MonadError m)
-> (forall a b.
MonadError m a -> (a -> MonadError m b) -> MonadError m b)
-> (forall a b. MonadError m a -> MonadError m b -> MonadError m b)
-> (forall a. a -> MonadError m a)
-> Monad (MonadError m)
MonadError m a -> (a -> MonadError m b) -> MonadError m b
MonadError m a -> MonadError m b -> MonadError m b
forall a. a -> MonadError m a
forall a b. MonadError m a -> MonadError m b -> MonadError m b
forall a b.
MonadError m a -> (a -> MonadError m b) -> MonadError m b
forall (m :: * -> *). Monad m => Applicative (MonadError m)
forall (m :: * -> *) a. Monad m => a -> MonadError m a
forall (m :: * -> *) a b.
Monad m =>
MonadError m a -> MonadError m b -> MonadError m b
forall (m :: * -> *) a b.
Monad m =>
MonadError m a -> (a -> MonadError m b) -> MonadError 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
return :: a -> MonadError m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> MonadError m a
>> :: MonadError m a -> MonadError m b -> MonadError m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
MonadError m a -> MonadError m b -> MonadError m b
>>= :: MonadError m a -> (a -> MonadError m b) -> MonadError m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
MonadError m a -> (a -> MonadError m b) -> MonadError m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (MonadError m)
Monad, Monad (MonadError m)
Monad (MonadError m)
-> (forall a. IO a -> MonadError m a) -> MonadIO (MonadError m)
IO a -> MonadError m a
forall a. IO a -> MonadError m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (MonadError m)
forall (m :: * -> *) a. MonadIO m => IO a -> MonadError m a
liftIO :: IO a -> MonadError m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> MonadError m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (MonadError m)
MonadIO, Monad (MonadError m)
Monad (MonadError m)
-> (forall a.
(State# (PrimState (MonadError m))
-> (# State# (PrimState (MonadError m)), a #))
-> MonadError m a)
-> PrimMonad (MonadError m)
(State# (PrimState (MonadError m))
-> (# State# (PrimState (MonadError m)), a #))
-> MonadError m a
forall a.
(State# (PrimState (MonadError m))
-> (# State# (PrimState (MonadError m)), a #))
-> MonadError m a
forall (m :: * -> *).
Monad m
-> (forall a.
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> PrimMonad m
forall (m :: * -> *). PrimMonad m => Monad (MonadError m)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (MonadError m))
-> (# State# (PrimState (MonadError m)), a #))
-> MonadError m a
primitive :: (State# (PrimState (MonadError m))
-> (# State# (PrimState (MonadError m)), a #))
-> MonadError m a
$cprimitive :: forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (MonadError m))
-> (# State# (PrimState (MonadError m)), a #))
-> MonadError m a
$cp1PrimMonad :: forall (m :: * -> *). PrimMonad m => Monad (MonadError m)
PrimMonad)
instance Except.MonadError e m => HasThrow tag e (MonadError m) where
throw_ :: forall a. Proxy# tag -> e -> MonadError m a
throw_ :: Proxy# tag -> e -> MonadError m a
throw_ Proxy# tag
_ = forall b. Coercible (e -> m a) b => (e -> m a) -> b
coerce @(e -> m a) ((e -> m a) -> e -> MonadError m a)
-> (e -> m a) -> e -> MonadError m a
forall a b. (a -> b) -> a -> b
$ e -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
Except.throwError
{-# INLINE throw_ #-}
instance Except.MonadError e m => HasCatch tag e (MonadError m) where
catch_ :: forall a.
Proxy# tag -> MonadError m a -> (e -> MonadError m a) -> MonadError m a
catch_ :: Proxy# tag
-> MonadError m a -> (e -> MonadError m a) -> MonadError m a
catch_ Proxy# tag
_ = forall b.
Coercible (m a -> (e -> m a) -> m a) b =>
(m a -> (e -> m a) -> m a) -> b
coerce @(m a -> (e -> m a) -> m a) ((m a -> (e -> m a) -> m a)
-> MonadError m a -> (e -> MonadError m a) -> MonadError m a)
-> (m a -> (e -> m a) -> m a)
-> MonadError m a
-> (e -> MonadError m a)
-> MonadError m a
forall a b. (a -> b) -> a -> b
$ m a -> (e -> m a) -> m a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
Except.catchError
{-# INLINE catch_ #-}
catchJust_ :: forall a b.
Proxy# tag
-> (e -> Maybe b)
-> MonadError m a
-> (b -> MonadError m a)
-> MonadError m a
catchJust_ :: Proxy# tag
-> (e -> Maybe b)
-> MonadError m a
-> (b -> MonadError m a)
-> MonadError m a
catchJust_ Proxy# tag
tag e -> Maybe b
f MonadError m a
m b -> MonadError m a
h = Proxy# tag
-> MonadError m a -> (e -> MonadError m a) -> MonadError m a
forall k (tag :: k) e (m :: * -> *) a.
HasCatch tag e m =>
Proxy# tag -> m a -> (e -> m a) -> m a
catch_ Proxy# tag
tag MonadError m a
m ((e -> MonadError m a) -> MonadError m a)
-> (e -> MonadError m a) -> MonadError m a
forall a b. (a -> b) -> a -> b
$ \e
e -> MonadError m a
-> (b -> MonadError m a) -> Maybe b -> MonadError m a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Proxy# tag -> e -> MonadError m a
forall k (tag :: k) e (m :: * -> *) a.
HasThrow tag e m =>
Proxy# tag -> e -> m a
throw_ Proxy# tag
tag e
e) b -> MonadError m a
h (Maybe b -> MonadError m a) -> Maybe b -> MonadError m a
forall a b. (a -> b) -> a -> b
$ e -> Maybe b
f e
e
{-# INLINE catchJust_ #-}
newtype MonadThrow (e :: Type) m (a :: Type) = MonadThrow (m a)
deriving (a -> MonadThrow e m b -> MonadThrow e m a
(a -> b) -> MonadThrow e m a -> MonadThrow e m b
(forall a b. (a -> b) -> MonadThrow e m a -> MonadThrow e m b)
-> (forall a b. a -> MonadThrow e m b -> MonadThrow e m a)
-> Functor (MonadThrow e m)
forall a b. a -> MonadThrow e m b -> MonadThrow e m a
forall a b. (a -> b) -> MonadThrow e m a -> MonadThrow e m b
forall e (m :: * -> *) a b.
Functor m =>
a -> MonadThrow e m b -> MonadThrow e m a
forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> MonadThrow e m a -> MonadThrow e m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MonadThrow e m b -> MonadThrow e m a
$c<$ :: forall e (m :: * -> *) a b.
Functor m =>
a -> MonadThrow e m b -> MonadThrow e m a
fmap :: (a -> b) -> MonadThrow e m a -> MonadThrow e m b
$cfmap :: forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> MonadThrow e m a -> MonadThrow e m b
Functor, Functor (MonadThrow e m)
a -> MonadThrow e m a
Functor (MonadThrow e m)
-> (forall a. a -> MonadThrow e m a)
-> (forall a b.
MonadThrow e m (a -> b) -> MonadThrow e m a -> MonadThrow e m b)
-> (forall a b c.
(a -> b -> c)
-> MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m c)
-> (forall a b.
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b)
-> (forall a b.
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m a)
-> Applicative (MonadThrow e m)
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m a
MonadThrow e m (a -> b) -> MonadThrow e m a -> MonadThrow e m b
(a -> b -> c)
-> MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m c
forall a. a -> MonadThrow e m a
forall a b.
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m a
forall a b.
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
forall a b.
MonadThrow e m (a -> b) -> MonadThrow e m a -> MonadThrow e m b
forall a b c.
(a -> b -> c)
-> MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m c
forall e (m :: * -> *). Applicative m => Functor (MonadThrow e m)
forall e (m :: * -> *) a. Applicative m => a -> MonadThrow e m a
forall e (m :: * -> *) a b.
Applicative m =>
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m a
forall e (m :: * -> *) a b.
Applicative m =>
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
forall e (m :: * -> *) a b.
Applicative m =>
MonadThrow e m (a -> b) -> MonadThrow e m a -> MonadThrow e m b
forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> MonadThrow e m a -> MonadThrow e m b -> MonadThrow e 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
<* :: MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m a
$c<* :: forall e (m :: * -> *) a b.
Applicative m =>
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m a
*> :: MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
$c*> :: forall e (m :: * -> *) a b.
Applicative m =>
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
liftA2 :: (a -> b -> c)
-> MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m c
$cliftA2 :: forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m c
<*> :: MonadThrow e m (a -> b) -> MonadThrow e m a -> MonadThrow e m b
$c<*> :: forall e (m :: * -> *) a b.
Applicative m =>
MonadThrow e m (a -> b) -> MonadThrow e m a -> MonadThrow e m b
pure :: a -> MonadThrow e m a
$cpure :: forall e (m :: * -> *) a. Applicative m => a -> MonadThrow e m a
$cp1Applicative :: forall e (m :: * -> *). Applicative m => Functor (MonadThrow e m)
Applicative, Applicative (MonadThrow e m)
a -> MonadThrow e m a
Applicative (MonadThrow e m)
-> (forall a b.
MonadThrow e m a -> (a -> MonadThrow e m b) -> MonadThrow e m b)
-> (forall a b.
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b)
-> (forall a. a -> MonadThrow e m a)
-> Monad (MonadThrow e m)
MonadThrow e m a -> (a -> MonadThrow e m b) -> MonadThrow e m b
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
forall a. a -> MonadThrow e m a
forall a b.
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
forall a b.
MonadThrow e m a -> (a -> MonadThrow e m b) -> MonadThrow e m b
forall e (m :: * -> *). Monad m => Applicative (MonadThrow e m)
forall e (m :: * -> *) a. Monad m => a -> MonadThrow e m a
forall e (m :: * -> *) a b.
Monad m =>
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
forall e (m :: * -> *) a b.
Monad m =>
MonadThrow e m a -> (a -> MonadThrow e m b) -> MonadThrow e 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
return :: a -> MonadThrow e m a
$creturn :: forall e (m :: * -> *) a. Monad m => a -> MonadThrow e m a
>> :: MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
$c>> :: forall e (m :: * -> *) a b.
Monad m =>
MonadThrow e m a -> MonadThrow e m b -> MonadThrow e m b
>>= :: MonadThrow e m a -> (a -> MonadThrow e m b) -> MonadThrow e m b
$c>>= :: forall e (m :: * -> *) a b.
Monad m =>
MonadThrow e m a -> (a -> MonadThrow e m b) -> MonadThrow e m b
$cp1Monad :: forall e (m :: * -> *). Monad m => Applicative (MonadThrow e m)
Monad, Monad (MonadThrow e m)
Monad (MonadThrow e m)
-> (forall a. IO a -> MonadThrow e m a) -> MonadIO (MonadThrow e m)
IO a -> MonadThrow e m a
forall a. IO a -> MonadThrow e m a
forall e (m :: * -> *). MonadIO m => Monad (MonadThrow e m)
forall e (m :: * -> *) a. MonadIO m => IO a -> MonadThrow e m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> MonadThrow e m a
$cliftIO :: forall e (m :: * -> *) a. MonadIO m => IO a -> MonadThrow e m a
$cp1MonadIO :: forall e (m :: * -> *). MonadIO m => Monad (MonadThrow e m)
MonadIO, Monad (MonadThrow e m)
Monad (MonadThrow e m)
-> (forall a.
(State# (PrimState (MonadThrow e m))
-> (# State# (PrimState (MonadThrow e m)), a #))
-> MonadThrow e m a)
-> PrimMonad (MonadThrow e m)
(State# (PrimState (MonadThrow e m))
-> (# State# (PrimState (MonadThrow e m)), a #))
-> MonadThrow e m a
forall a.
(State# (PrimState (MonadThrow e m))
-> (# State# (PrimState (MonadThrow e m)), a #))
-> MonadThrow e m a
forall e (m :: * -> *). PrimMonad m => Monad (MonadThrow e m)
forall e (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (MonadThrow e m))
-> (# State# (PrimState (MonadThrow e m)), a #))
-> MonadThrow e m a
forall (m :: * -> *).
Monad m
-> (forall a.
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> PrimMonad m
primitive :: (State# (PrimState (MonadThrow e m))
-> (# State# (PrimState (MonadThrow e m)), a #))
-> MonadThrow e m a
$cprimitive :: forall e (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (MonadThrow e m))
-> (# State# (PrimState (MonadThrow e m)), a #))
-> MonadThrow e m a
$cp1PrimMonad :: forall e (m :: * -> *). PrimMonad m => Monad (MonadThrow e m)
PrimMonad)
instance (Catch.Exception e, Catch.MonadThrow m)
=> HasThrow tag e (MonadThrow e m)
where
throw_ :: forall a. Proxy# tag -> e -> MonadThrow e m a
throw_ :: Proxy# tag -> e -> MonadThrow e m a
throw_ Proxy# tag
_ = forall b. Coercible (e -> m a) b => (e -> m a) -> b
coerce @(e -> m a) ((e -> m a) -> e -> MonadThrow e m a)
-> (e -> m a) -> e -> MonadThrow e m a
forall a b. (a -> b) -> a -> b
$ e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
Catch.throwM
{-# INLINE throw_ #-}
newtype MonadCatch (e :: Type) m (a :: Type) = MonadCatch (m a)
deriving (a -> MonadCatch e m b -> MonadCatch e m a
(a -> b) -> MonadCatch e m a -> MonadCatch e m b
(forall a b. (a -> b) -> MonadCatch e m a -> MonadCatch e m b)
-> (forall a b. a -> MonadCatch e m b -> MonadCatch e m a)
-> Functor (MonadCatch e m)
forall a b. a -> MonadCatch e m b -> MonadCatch e m a
forall a b. (a -> b) -> MonadCatch e m a -> MonadCatch e m b
forall e (m :: * -> *) a b.
Functor m =>
a -> MonadCatch e m b -> MonadCatch e m a
forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> MonadCatch e m a -> MonadCatch e m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MonadCatch e m b -> MonadCatch e m a
$c<$ :: forall e (m :: * -> *) a b.
Functor m =>
a -> MonadCatch e m b -> MonadCatch e m a
fmap :: (a -> b) -> MonadCatch e m a -> MonadCatch e m b
$cfmap :: forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> MonadCatch e m a -> MonadCatch e m b
Functor, Functor (MonadCatch e m)
a -> MonadCatch e m a
Functor (MonadCatch e m)
-> (forall a. a -> MonadCatch e m a)
-> (forall a b.
MonadCatch e m (a -> b) -> MonadCatch e m a -> MonadCatch e m b)
-> (forall a b c.
(a -> b -> c)
-> MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m c)
-> (forall a b.
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b)
-> (forall a b.
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m a)
-> Applicative (MonadCatch e m)
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m a
MonadCatch e m (a -> b) -> MonadCatch e m a -> MonadCatch e m b
(a -> b -> c)
-> MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m c
forall a. a -> MonadCatch e m a
forall a b.
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m a
forall a b.
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
forall a b.
MonadCatch e m (a -> b) -> MonadCatch e m a -> MonadCatch e m b
forall a b c.
(a -> b -> c)
-> MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m c
forall e (m :: * -> *). Applicative m => Functor (MonadCatch e m)
forall e (m :: * -> *) a. Applicative m => a -> MonadCatch e m a
forall e (m :: * -> *) a b.
Applicative m =>
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m a
forall e (m :: * -> *) a b.
Applicative m =>
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
forall e (m :: * -> *) a b.
Applicative m =>
MonadCatch e m (a -> b) -> MonadCatch e m a -> MonadCatch e m b
forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> MonadCatch e m a -> MonadCatch e m b -> MonadCatch e 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
<* :: MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m a
$c<* :: forall e (m :: * -> *) a b.
Applicative m =>
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m a
*> :: MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
$c*> :: forall e (m :: * -> *) a b.
Applicative m =>
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
liftA2 :: (a -> b -> c)
-> MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m c
$cliftA2 :: forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m c
<*> :: MonadCatch e m (a -> b) -> MonadCatch e m a -> MonadCatch e m b
$c<*> :: forall e (m :: * -> *) a b.
Applicative m =>
MonadCatch e m (a -> b) -> MonadCatch e m a -> MonadCatch e m b
pure :: a -> MonadCatch e m a
$cpure :: forall e (m :: * -> *) a. Applicative m => a -> MonadCatch e m a
$cp1Applicative :: forall e (m :: * -> *). Applicative m => Functor (MonadCatch e m)
Applicative, Applicative (MonadCatch e m)
a -> MonadCatch e m a
Applicative (MonadCatch e m)
-> (forall a b.
MonadCatch e m a -> (a -> MonadCatch e m b) -> MonadCatch e m b)
-> (forall a b.
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b)
-> (forall a. a -> MonadCatch e m a)
-> Monad (MonadCatch e m)
MonadCatch e m a -> (a -> MonadCatch e m b) -> MonadCatch e m b
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
forall a. a -> MonadCatch e m a
forall a b.
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
forall a b.
MonadCatch e m a -> (a -> MonadCatch e m b) -> MonadCatch e m b
forall e (m :: * -> *). Monad m => Applicative (MonadCatch e m)
forall e (m :: * -> *) a. Monad m => a -> MonadCatch e m a
forall e (m :: * -> *) a b.
Monad m =>
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
forall e (m :: * -> *) a b.
Monad m =>
MonadCatch e m a -> (a -> MonadCatch e m b) -> MonadCatch e 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
return :: a -> MonadCatch e m a
$creturn :: forall e (m :: * -> *) a. Monad m => a -> MonadCatch e m a
>> :: MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
$c>> :: forall e (m :: * -> *) a b.
Monad m =>
MonadCatch e m a -> MonadCatch e m b -> MonadCatch e m b
>>= :: MonadCatch e m a -> (a -> MonadCatch e m b) -> MonadCatch e m b
$c>>= :: forall e (m :: * -> *) a b.
Monad m =>
MonadCatch e m a -> (a -> MonadCatch e m b) -> MonadCatch e m b
$cp1Monad :: forall e (m :: * -> *). Monad m => Applicative (MonadCatch e m)
Monad, Monad (MonadCatch e m)
Monad (MonadCatch e m)
-> (forall a. IO a -> MonadCatch e m a) -> MonadIO (MonadCatch e m)
IO a -> MonadCatch e m a
forall a. IO a -> MonadCatch e m a
forall e (m :: * -> *). MonadIO m => Monad (MonadCatch e m)
forall e (m :: * -> *) a. MonadIO m => IO a -> MonadCatch e m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> MonadCatch e m a
$cliftIO :: forall e (m :: * -> *) a. MonadIO m => IO a -> MonadCatch e m a
$cp1MonadIO :: forall e (m :: * -> *). MonadIO m => Monad (MonadCatch e m)
MonadIO, Monad (MonadCatch e m)
Monad (MonadCatch e m)
-> (forall a.
(State# (PrimState (MonadCatch e m))
-> (# State# (PrimState (MonadCatch e m)), a #))
-> MonadCatch e m a)
-> PrimMonad (MonadCatch e m)
(State# (PrimState (MonadCatch e m))
-> (# State# (PrimState (MonadCatch e m)), a #))
-> MonadCatch e m a
forall a.
(State# (PrimState (MonadCatch e m))
-> (# State# (PrimState (MonadCatch e m)), a #))
-> MonadCatch e m a
forall e (m :: * -> *). PrimMonad m => Monad (MonadCatch e m)
forall e (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (MonadCatch e m))
-> (# State# (PrimState (MonadCatch e m)), a #))
-> MonadCatch e m a
forall (m :: * -> *).
Monad m
-> (forall a.
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> PrimMonad m
primitive :: (State# (PrimState (MonadCatch e m))
-> (# State# (PrimState (MonadCatch e m)), a #))
-> MonadCatch e m a
$cprimitive :: forall e (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (MonadCatch e m))
-> (# State# (PrimState (MonadCatch e m)), a #))
-> MonadCatch e m a
$cp1PrimMonad :: forall e (m :: * -> *). PrimMonad m => Monad (MonadCatch e m)
PrimMonad)
deriving (HasThrow tag e) via MonadThrow e m
instance (Catch.Exception e, Catch.MonadCatch m)
=> HasCatch tag e (MonadCatch e m)
where
catch_ :: forall a.
Proxy# tag
-> MonadCatch e m a
-> (e -> MonadCatch e m a)
-> MonadCatch e m a
catch_ :: Proxy# tag
-> MonadCatch e m a -> (e -> MonadCatch e m a) -> MonadCatch e m a
catch_ Proxy# tag
_ = forall b.
Coercible (m a -> (e -> m a) -> m a) b =>
(m a -> (e -> m a) -> m a) -> b
coerce @(m a -> (e -> m a) -> m a) ((m a -> (e -> m a) -> m a)
-> MonadCatch e m a -> (e -> MonadCatch e m a) -> MonadCatch e m a)
-> (m a -> (e -> m a) -> m a)
-> MonadCatch e m a
-> (e -> MonadCatch e m a)
-> MonadCatch e m a
forall a b. (a -> b) -> a -> b
$ m a -> (e -> m a) -> m a
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
Catch.catch
{-# INLINE catch_ #-}
catchJust_ :: forall a b.
Proxy# tag
-> (e -> Maybe b)
-> MonadCatch e m a
-> (b -> MonadCatch e m a)
-> MonadCatch e m a
catchJust_ :: Proxy# tag
-> (e -> Maybe b)
-> MonadCatch e m a
-> (b -> MonadCatch e m a)
-> MonadCatch e m a
catchJust_ Proxy# tag
_ = forall b.
Coercible ((e -> Maybe b) -> m a -> (b -> m a) -> m a) b =>
((e -> Maybe b) -> m a -> (b -> m a) -> m a) -> b
coerce @((e -> Maybe b) -> m a -> (b -> m a) -> m a) (((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> MonadCatch e m a
-> (b -> MonadCatch e m a)
-> MonadCatch e m a)
-> ((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> MonadCatch e m a
-> (b -> MonadCatch e m a)
-> MonadCatch e m a
forall a b. (a -> b) -> a -> b
$
(e -> Maybe b) -> m a -> (b -> m a) -> m a
forall (m :: * -> *) e b a.
(MonadCatch m, Exception e) =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
Catch.catchJust
{-# INLINE catchJust_ #-}
newtype SafeExceptions (e :: Type) m (a :: Type) = SafeExceptions (m a)
deriving (a -> SafeExceptions e m b -> SafeExceptions e m a
(a -> b) -> SafeExceptions e m a -> SafeExceptions e m b
(forall a b.
(a -> b) -> SafeExceptions e m a -> SafeExceptions e m b)
-> (forall a b. a -> SafeExceptions e m b -> SafeExceptions e m a)
-> Functor (SafeExceptions e m)
forall a b. a -> SafeExceptions e m b -> SafeExceptions e m a
forall a b.
(a -> b) -> SafeExceptions e m a -> SafeExceptions e m b
forall e (m :: * -> *) a b.
Functor m =>
a -> SafeExceptions e m b -> SafeExceptions e m a
forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> SafeExceptions e m a -> SafeExceptions e m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> SafeExceptions e m b -> SafeExceptions e m a
$c<$ :: forall e (m :: * -> *) a b.
Functor m =>
a -> SafeExceptions e m b -> SafeExceptions e m a
fmap :: (a -> b) -> SafeExceptions e m a -> SafeExceptions e m b
$cfmap :: forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> SafeExceptions e m a -> SafeExceptions e m b
Functor, Functor (SafeExceptions e m)
a -> SafeExceptions e m a
Functor (SafeExceptions e m)
-> (forall a. a -> SafeExceptions e m a)
-> (forall a b.
SafeExceptions e m (a -> b)
-> SafeExceptions e m a -> SafeExceptions e m b)
-> (forall a b c.
(a -> b -> c)
-> SafeExceptions e m a
-> SafeExceptions e m b
-> SafeExceptions e m c)
-> (forall a b.
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b)
-> (forall a b.
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m a)
-> Applicative (SafeExceptions e m)
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m a
SafeExceptions e m (a -> b)
-> SafeExceptions e m a -> SafeExceptions e m b
(a -> b -> c)
-> SafeExceptions e m a
-> SafeExceptions e m b
-> SafeExceptions e m c
forall a. a -> SafeExceptions e m a
forall a b.
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m a
forall a b.
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
forall a b.
SafeExceptions e m (a -> b)
-> SafeExceptions e m a -> SafeExceptions e m b
forall a b c.
(a -> b -> c)
-> SafeExceptions e m a
-> SafeExceptions e m b
-> SafeExceptions e m c
forall e (m :: * -> *).
Applicative m =>
Functor (SafeExceptions e m)
forall e (m :: * -> *) a.
Applicative m =>
a -> SafeExceptions e m a
forall e (m :: * -> *) a b.
Applicative m =>
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m a
forall e (m :: * -> *) a b.
Applicative m =>
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
forall e (m :: * -> *) a b.
Applicative m =>
SafeExceptions e m (a -> b)
-> SafeExceptions e m a -> SafeExceptions e m b
forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> SafeExceptions e m a
-> SafeExceptions e m b
-> SafeExceptions e 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
<* :: SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m a
$c<* :: forall e (m :: * -> *) a b.
Applicative m =>
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m a
*> :: SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
$c*> :: forall e (m :: * -> *) a b.
Applicative m =>
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
liftA2 :: (a -> b -> c)
-> SafeExceptions e m a
-> SafeExceptions e m b
-> SafeExceptions e m c
$cliftA2 :: forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> SafeExceptions e m a
-> SafeExceptions e m b
-> SafeExceptions e m c
<*> :: SafeExceptions e m (a -> b)
-> SafeExceptions e m a -> SafeExceptions e m b
$c<*> :: forall e (m :: * -> *) a b.
Applicative m =>
SafeExceptions e m (a -> b)
-> SafeExceptions e m a -> SafeExceptions e m b
pure :: a -> SafeExceptions e m a
$cpure :: forall e (m :: * -> *) a.
Applicative m =>
a -> SafeExceptions e m a
$cp1Applicative :: forall e (m :: * -> *).
Applicative m =>
Functor (SafeExceptions e m)
Applicative, Applicative (SafeExceptions e m)
a -> SafeExceptions e m a
Applicative (SafeExceptions e m)
-> (forall a b.
SafeExceptions e m a
-> (a -> SafeExceptions e m b) -> SafeExceptions e m b)
-> (forall a b.
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b)
-> (forall a. a -> SafeExceptions e m a)
-> Monad (SafeExceptions e m)
SafeExceptions e m a
-> (a -> SafeExceptions e m b) -> SafeExceptions e m b
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
forall a. a -> SafeExceptions e m a
forall a b.
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
forall a b.
SafeExceptions e m a
-> (a -> SafeExceptions e m b) -> SafeExceptions e m b
forall e (m :: * -> *). Monad m => Applicative (SafeExceptions e m)
forall e (m :: * -> *) a. Monad m => a -> SafeExceptions e m a
forall e (m :: * -> *) a b.
Monad m =>
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
forall e (m :: * -> *) a b.
Monad m =>
SafeExceptions e m a
-> (a -> SafeExceptions e m b) -> SafeExceptions e 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
return :: a -> SafeExceptions e m a
$creturn :: forall e (m :: * -> *) a. Monad m => a -> SafeExceptions e m a
>> :: SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
$c>> :: forall e (m :: * -> *) a b.
Monad m =>
SafeExceptions e m a
-> SafeExceptions e m b -> SafeExceptions e m b
>>= :: SafeExceptions e m a
-> (a -> SafeExceptions e m b) -> SafeExceptions e m b
$c>>= :: forall e (m :: * -> *) a b.
Monad m =>
SafeExceptions e m a
-> (a -> SafeExceptions e m b) -> SafeExceptions e m b
$cp1Monad :: forall e (m :: * -> *). Monad m => Applicative (SafeExceptions e m)
Monad, Monad (SafeExceptions e m)
Monad (SafeExceptions e m)
-> (forall a. IO a -> SafeExceptions e m a)
-> MonadIO (SafeExceptions e m)
IO a -> SafeExceptions e m a
forall a. IO a -> SafeExceptions e m a
forall e (m :: * -> *). MonadIO m => Monad (SafeExceptions e m)
forall e (m :: * -> *) a. MonadIO m => IO a -> SafeExceptions e m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> SafeExceptions e m a
$cliftIO :: forall e (m :: * -> *) a. MonadIO m => IO a -> SafeExceptions e m a
$cp1MonadIO :: forall e (m :: * -> *). MonadIO m => Monad (SafeExceptions e m)
MonadIO, Monad (SafeExceptions e m)
Monad (SafeExceptions e m)
-> (forall a.
(State# (PrimState (SafeExceptions e m))
-> (# State# (PrimState (SafeExceptions e m)), a #))
-> SafeExceptions e m a)
-> PrimMonad (SafeExceptions e m)
(State# (PrimState (SafeExceptions e m))
-> (# State# (PrimState (SafeExceptions e m)), a #))
-> SafeExceptions e m a
forall a.
(State# (PrimState (SafeExceptions e m))
-> (# State# (PrimState (SafeExceptions e m)), a #))
-> SafeExceptions e m a
forall e (m :: * -> *). PrimMonad m => Monad (SafeExceptions e m)
forall e (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (SafeExceptions e m))
-> (# State# (PrimState (SafeExceptions e m)), a #))
-> SafeExceptions e m a
forall (m :: * -> *).
Monad m
-> (forall a.
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> PrimMonad m
primitive :: (State# (PrimState (SafeExceptions e m))
-> (# State# (PrimState (SafeExceptions e m)), a #))
-> SafeExceptions e m a
$cprimitive :: forall e (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (SafeExceptions e m))
-> (# State# (PrimState (SafeExceptions e m)), a #))
-> SafeExceptions e m a
$cp1PrimMonad :: forall e (m :: * -> *). PrimMonad m => Monad (SafeExceptions e m)
PrimMonad)
instance (Safe.Exception e, Safe.MonadThrow m)
=> HasThrow tag e (SafeExceptions e m)
where
throw_ :: forall a. Proxy# tag -> e -> SafeExceptions e m a
throw_ :: Proxy# tag -> e -> SafeExceptions e m a
throw_ Proxy# tag
_ = forall b. Coercible (e -> m a) b => (e -> m a) -> b
coerce @(e -> m a) ((e -> m a) -> e -> SafeExceptions e m a)
-> (e -> m a) -> e -> SafeExceptions e m a
forall a b. (a -> b) -> a -> b
$ e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
Safe.throw
{-# INLINE throw_ #-}
instance (Safe.Exception e, Safe.MonadCatch m)
=> HasCatch tag e (SafeExceptions e m)
where
catch_ :: forall a.
Proxy# tag
-> SafeExceptions e m a
-> (e -> SafeExceptions e m a)
-> SafeExceptions e m a
catch_ :: Proxy# tag
-> SafeExceptions e m a
-> (e -> SafeExceptions e m a)
-> SafeExceptions e m a
catch_ Proxy# tag
_ = forall b.
Coercible (m a -> (e -> m a) -> m a) b =>
(m a -> (e -> m a) -> m a) -> b
coerce @(m a -> (e -> m a) -> m a) ((m a -> (e -> m a) -> m a)
-> SafeExceptions e m a
-> (e -> SafeExceptions e m a)
-> SafeExceptions e m a)
-> (m a -> (e -> m a) -> m a)
-> SafeExceptions e m a
-> (e -> SafeExceptions e m a)
-> SafeExceptions e m a
forall a b. (a -> b) -> a -> b
$ m a -> (e -> m a) -> m a
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
Safe.catch
{-# INLINE catch_ #-}
catchJust_ :: forall a b.
Proxy# tag
-> (e -> Maybe b)
-> SafeExceptions e m a
-> (b -> SafeExceptions e m a)
-> SafeExceptions e m a
catchJust_ :: Proxy# tag
-> (e -> Maybe b)
-> SafeExceptions e m a
-> (b -> SafeExceptions e m a)
-> SafeExceptions e m a
catchJust_ Proxy# tag
_ = forall b.
Coercible ((e -> Maybe b) -> m a -> (b -> m a) -> m a) b =>
((e -> Maybe b) -> m a -> (b -> m a) -> m a) -> b
coerce @((e -> Maybe b) -> m a -> (b -> m a) -> m a) (((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> SafeExceptions e m a
-> (b -> SafeExceptions e m a)
-> SafeExceptions e m a)
-> ((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> SafeExceptions e m a
-> (b -> SafeExceptions e m a)
-> SafeExceptions e m a
forall a b. (a -> b) -> a -> b
$
(e -> Maybe b) -> m a -> (b -> m a) -> m a
forall (m :: * -> *) e b a.
(MonadCatch m, Exception e) =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
Safe.catchJust
{-# INLINE catchJust_ #-}
newtype MonadUnliftIO (e :: Type) m (a :: Type) = MonadUnliftIO (m a)
deriving (a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
(a -> b) -> MonadUnliftIO e m a -> MonadUnliftIO e m b
(forall a b.
(a -> b) -> MonadUnliftIO e m a -> MonadUnliftIO e m b)
-> (forall a b. a -> MonadUnliftIO e m b -> MonadUnliftIO e m a)
-> Functor (MonadUnliftIO e m)
forall a b. a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
forall a b. (a -> b) -> MonadUnliftIO e m a -> MonadUnliftIO e m b
forall e (m :: * -> *) a b.
Functor m =>
a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> MonadUnliftIO e m a -> MonadUnliftIO e m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
$c<$ :: forall e (m :: * -> *) a b.
Functor m =>
a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
fmap :: (a -> b) -> MonadUnliftIO e m a -> MonadUnliftIO e m b
$cfmap :: forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> MonadUnliftIO e m a -> MonadUnliftIO e m b
Functor, Functor (MonadUnliftIO e m)
a -> MonadUnliftIO e m a
Functor (MonadUnliftIO e m)
-> (forall a. a -> MonadUnliftIO e m a)
-> (forall a b.
MonadUnliftIO e m (a -> b)
-> MonadUnliftIO e m a -> MonadUnliftIO e m b)
-> (forall a b c.
(a -> b -> c)
-> MonadUnliftIO e m a
-> MonadUnliftIO e m b
-> MonadUnliftIO e m c)
-> (forall a b.
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b)
-> (forall a b.
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m a)
-> Applicative (MonadUnliftIO e m)
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
MonadUnliftIO e m (a -> b)
-> MonadUnliftIO e m a -> MonadUnliftIO e m b
(a -> b -> c)
-> MonadUnliftIO e m a
-> MonadUnliftIO e m b
-> MonadUnliftIO e m c
forall a. a -> MonadUnliftIO e m a
forall a b.
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
forall a b.
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
forall a b.
MonadUnliftIO e m (a -> b)
-> MonadUnliftIO e m a -> MonadUnliftIO e m b
forall a b c.
(a -> b -> c)
-> MonadUnliftIO e m a
-> MonadUnliftIO e m b
-> MonadUnliftIO e m c
forall e (m :: * -> *).
Applicative m =>
Functor (MonadUnliftIO e m)
forall e (m :: * -> *) a. Applicative m => a -> MonadUnliftIO e m a
forall e (m :: * -> *) a b.
Applicative m =>
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
forall e (m :: * -> *) a b.
Applicative m =>
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
forall e (m :: * -> *) a b.
Applicative m =>
MonadUnliftIO e m (a -> b)
-> MonadUnliftIO e m a -> MonadUnliftIO e m b
forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> MonadUnliftIO e m a
-> MonadUnliftIO e m b
-> MonadUnliftIO e 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
<* :: MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
$c<* :: forall e (m :: * -> *) a b.
Applicative m =>
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m a
*> :: MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
$c*> :: forall e (m :: * -> *) a b.
Applicative m =>
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
liftA2 :: (a -> b -> c)
-> MonadUnliftIO e m a
-> MonadUnliftIO e m b
-> MonadUnliftIO e m c
$cliftA2 :: forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> MonadUnliftIO e m a
-> MonadUnliftIO e m b
-> MonadUnliftIO e m c
<*> :: MonadUnliftIO e m (a -> b)
-> MonadUnliftIO e m a -> MonadUnliftIO e m b
$c<*> :: forall e (m :: * -> *) a b.
Applicative m =>
MonadUnliftIO e m (a -> b)
-> MonadUnliftIO e m a -> MonadUnliftIO e m b
pure :: a -> MonadUnliftIO e m a
$cpure :: forall e (m :: * -> *) a. Applicative m => a -> MonadUnliftIO e m a
$cp1Applicative :: forall e (m :: * -> *).
Applicative m =>
Functor (MonadUnliftIO e m)
Applicative, Applicative (MonadUnliftIO e m)
a -> MonadUnliftIO e m a
Applicative (MonadUnliftIO e m)
-> (forall a b.
MonadUnliftIO e m a
-> (a -> MonadUnliftIO e m b) -> MonadUnliftIO e m b)
-> (forall a b.
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b)
-> (forall a. a -> MonadUnliftIO e m a)
-> Monad (MonadUnliftIO e m)
MonadUnliftIO e m a
-> (a -> MonadUnliftIO e m b) -> MonadUnliftIO e m b
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
forall a. a -> MonadUnliftIO e m a
forall a b.
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
forall a b.
MonadUnliftIO e m a
-> (a -> MonadUnliftIO e m b) -> MonadUnliftIO e m b
forall e (m :: * -> *). Monad m => Applicative (MonadUnliftIO e m)
forall e (m :: * -> *) a. Monad m => a -> MonadUnliftIO e m a
forall e (m :: * -> *) a b.
Monad m =>
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
forall e (m :: * -> *) a b.
Monad m =>
MonadUnliftIO e m a
-> (a -> MonadUnliftIO e m b) -> MonadUnliftIO e 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
return :: a -> MonadUnliftIO e m a
$creturn :: forall e (m :: * -> *) a. Monad m => a -> MonadUnliftIO e m a
>> :: MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
$c>> :: forall e (m :: * -> *) a b.
Monad m =>
MonadUnliftIO e m a -> MonadUnliftIO e m b -> MonadUnliftIO e m b
>>= :: MonadUnliftIO e m a
-> (a -> MonadUnliftIO e m b) -> MonadUnliftIO e m b
$c>>= :: forall e (m :: * -> *) a b.
Monad m =>
MonadUnliftIO e m a
-> (a -> MonadUnliftIO e m b) -> MonadUnliftIO e m b
$cp1Monad :: forall e (m :: * -> *). Monad m => Applicative (MonadUnliftIO e m)
Monad, Monad (MonadUnliftIO e m)
Monad (MonadUnliftIO e m)
-> (forall a. IO a -> MonadUnliftIO e m a)
-> MonadIO (MonadUnliftIO e m)
IO a -> MonadUnliftIO e m a
forall a. IO a -> MonadUnliftIO e m a
forall e (m :: * -> *). MonadIO m => Monad (MonadUnliftIO e m)
forall e (m :: * -> *) a. MonadIO m => IO a -> MonadUnliftIO e m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> MonadUnliftIO e m a
$cliftIO :: forall e (m :: * -> *) a. MonadIO m => IO a -> MonadUnliftIO e m a
$cp1MonadIO :: forall e (m :: * -> *). MonadIO m => Monad (MonadUnliftIO e m)
MonadIO, Monad (MonadUnliftIO e m)
Monad (MonadUnliftIO e m)
-> (forall a.
(State# (PrimState (MonadUnliftIO e m))
-> (# State# (PrimState (MonadUnliftIO e m)), a #))
-> MonadUnliftIO e m a)
-> PrimMonad (MonadUnliftIO e m)
(State# (PrimState (MonadUnliftIO e m))
-> (# State# (PrimState (MonadUnliftIO e m)), a #))
-> MonadUnliftIO e m a
forall a.
(State# (PrimState (MonadUnliftIO e m))
-> (# State# (PrimState (MonadUnliftIO e m)), a #))
-> MonadUnliftIO e m a
forall e (m :: * -> *). PrimMonad m => Monad (MonadUnliftIO e m)
forall e (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (MonadUnliftIO e m))
-> (# State# (PrimState (MonadUnliftIO e m)), a #))
-> MonadUnliftIO e m a
forall (m :: * -> *).
Monad m
-> (forall a.
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> PrimMonad m
primitive :: (State# (PrimState (MonadUnliftIO e m))
-> (# State# (PrimState (MonadUnliftIO e m)), a #))
-> MonadUnliftIO e m a
$cprimitive :: forall e (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (MonadUnliftIO e m))
-> (# State# (PrimState (MonadUnliftIO e m)), a #))
-> MonadUnliftIO e m a
$cp1PrimMonad :: forall e (m :: * -> *). PrimMonad m => Monad (MonadUnliftIO e m)
PrimMonad)
instance (UnliftIO.Exception e, MonadIO m)
=> HasThrow tag e (MonadUnliftIO e m)
where
throw_ :: forall a. Proxy# tag -> e -> MonadUnliftIO e m a
throw_ :: Proxy# tag -> e -> MonadUnliftIO e m a
throw_ Proxy# tag
_ = forall b. Coercible (e -> m a) b => (e -> m a) -> b
coerce @(e -> m a) ((e -> m a) -> e -> MonadUnliftIO e m a)
-> (e -> m a) -> e -> MonadUnliftIO e m a
forall a b. (a -> b) -> a -> b
$ e -> m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
UnliftIO.throwIO
{-# INLINE throw_ #-}
instance (UnliftIO.Exception e, UnliftIO.MonadUnliftIO m)
=> HasCatch tag e (MonadUnliftIO e m)
where
catch_ :: forall a.
Proxy# tag
-> MonadUnliftIO e m a
-> (e -> MonadUnliftIO e m a)
-> MonadUnliftIO e m a
catch_ :: Proxy# tag
-> MonadUnliftIO e m a
-> (e -> MonadUnliftIO e m a)
-> MonadUnliftIO e m a
catch_ Proxy# tag
_ = forall b.
Coercible (m a -> (e -> m a) -> m a) b =>
(m a -> (e -> m a) -> m a) -> b
coerce @(m a -> (e -> m a) -> m a) ((m a -> (e -> m a) -> m a)
-> MonadUnliftIO e m a
-> (e -> MonadUnliftIO e m a)
-> MonadUnliftIO e m a)
-> (m a -> (e -> m a) -> m a)
-> MonadUnliftIO e m a
-> (e -> MonadUnliftIO e m a)
-> MonadUnliftIO e m a
forall a b. (a -> b) -> a -> b
$ m a -> (e -> m a) -> m a
forall (m :: * -> *) e a.
(MonadUnliftIO m, Exception e) =>
m a -> (e -> m a) -> m a
UnliftIO.catch
{-# INLINE catch_ #-}
catchJust_ :: forall a b.
Proxy# tag
-> (e -> Maybe b)
-> MonadUnliftIO e m a
-> (b -> MonadUnliftIO e m a)
-> MonadUnliftIO e m a
catchJust_ :: Proxy# tag
-> (e -> Maybe b)
-> MonadUnliftIO e m a
-> (b -> MonadUnliftIO e m a)
-> MonadUnliftIO e m a
catchJust_ Proxy# tag
_ = forall b.
Coercible ((e -> Maybe b) -> m a -> (b -> m a) -> m a) b =>
((e -> Maybe b) -> m a -> (b -> m a) -> m a) -> b
coerce @((e -> Maybe b) -> m a -> (b -> m a) -> m a) (((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> MonadUnliftIO e m a
-> (b -> MonadUnliftIO e m a)
-> MonadUnliftIO e m a)
-> ((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> MonadUnliftIO e m a
-> (b -> MonadUnliftIO e m a)
-> MonadUnliftIO e m a
forall a b. (a -> b) -> a -> b
$
(e -> Maybe b) -> m a -> (b -> m a) -> m a
forall (m :: * -> *) e b a.
(MonadUnliftIO m, Exception e) =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
UnliftIO.catchJust
{-# INLINE catchJust_ #-}
instance HasThrow oldtag e m => HasThrow newtag e (Rename oldtag m) where
throw_ :: forall a. Proxy# newtag -> e -> Rename oldtag m a
throw_ :: Proxy# newtag -> e -> Rename oldtag m a
throw_ Proxy# newtag
_ = forall b. Coercible (e -> m a) b => (e -> m a) -> b
coerce @(e -> m a) ((e -> m a) -> e -> Rename oldtag m a)
-> (e -> m a) -> e -> Rename oldtag m a
forall a b. (a -> b) -> a -> b
$ forall k (tag :: k) e (m :: * -> *) a. HasThrow tag e m => e -> m a
forall e (m :: * -> *) a. HasThrow oldtag e m => e -> m a
throw @oldtag
{-# INLINE throw_ #-}
instance HasCatch oldtag e m => HasCatch newtag e (Rename oldtag m) where
catch_ :: forall a.
Proxy# newtag
-> Rename oldtag m a
-> (e -> Rename oldtag m a)
-> Rename oldtag m a
catch_ :: Proxy# newtag
-> Rename oldtag m a
-> (e -> Rename oldtag m a)
-> Rename oldtag m a
catch_ Proxy# newtag
_ = forall b.
Coercible (m a -> (e -> m a) -> m a) b =>
(m a -> (e -> m a) -> m a) -> b
coerce @(m a -> (e -> m a) -> m a) ((m a -> (e -> m a) -> m a)
-> Rename oldtag m a
-> (e -> Rename oldtag m a)
-> Rename oldtag m a)
-> (m a -> (e -> m a) -> m a)
-> Rename oldtag m a
-> (e -> Rename oldtag m a)
-> Rename oldtag m a
forall a b. (a -> b) -> a -> b
$ forall k (tag :: k) e (m :: * -> *) a.
HasCatch tag e m =>
m a -> (e -> m a) -> m a
forall e (m :: * -> *) a.
HasCatch oldtag e m =>
m a -> (e -> m a) -> m a
catch @oldtag
{-# INLINE catch_ #-}
catchJust_ :: forall a b.
Proxy# newtag
-> (e -> Maybe b)
-> Rename oldtag m a
-> (b -> Rename oldtag m a)
-> Rename oldtag m a
catchJust_ :: Proxy# newtag
-> (e -> Maybe b)
-> Rename oldtag m a
-> (b -> Rename oldtag m a)
-> Rename oldtag m a
catchJust_ Proxy# newtag
_ = forall b.
Coercible ((e -> Maybe b) -> m a -> (b -> m a) -> m a) b =>
((e -> Maybe b) -> m a -> (b -> m a) -> m a) -> b
coerce @((e -> Maybe b) -> m a -> (b -> m a) -> m a) (((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> Rename oldtag m a
-> (b -> Rename oldtag m a)
-> Rename oldtag m a)
-> ((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> Rename oldtag m a
-> (b -> Rename oldtag m a)
-> Rename oldtag m a
forall a b. (a -> b) -> a -> b
$
forall k (tag :: k) e (m :: * -> *) a b.
HasCatch tag e m =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
forall e (m :: * -> *) a b.
HasCatch oldtag e m =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust @oldtag
{-# INLINE catchJust_ #-}
instance
(Generic.AsConstructor' ctor sum e, HasThrow oldtag sum m)
=> HasThrow ctor e (Ctor ctor oldtag m)
where
throw_ :: forall a. Proxy# ctor -> e -> Ctor ctor oldtag m a
throw_ :: Proxy# ctor -> e -> Ctor ctor oldtag m a
throw_ Proxy# ctor
_ = forall b. Coercible (e -> m a) b => (e -> m a) -> b
coerce @(e -> m a) ((e -> m a) -> e -> Ctor ctor oldtag m a)
-> (e -> m a) -> e -> Ctor ctor oldtag m a
forall a b. (a -> b) -> a -> b
$
forall k (tag :: k) e (m :: * -> *) a. HasThrow tag e m => e -> m a
forall e (m :: * -> *) a. HasThrow oldtag e m => e -> m a
throw @oldtag (sum -> m a) -> (e -> sum) -> e -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AReview sum e -> e -> sum
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review (forall a. AsConstructor' ctor sum a => Prism sum sum a a
forall (ctor :: Symbol) s a.
AsConstructor' ctor s a =>
Prism s s a a
Generic._Ctor' @ctor @sum)
{-# INLINE throw_ #-}
instance
(Generic.AsConstructor' ctor sum e, HasCatch oldtag sum m)
=> HasCatch ctor e (Ctor ctor oldtag m)
where
catch_ :: forall a.
Proxy# ctor
-> Ctor ctor oldtag m a
-> (e -> Ctor ctor oldtag m a)
-> Ctor ctor oldtag m a
catch_ :: Proxy# ctor
-> Ctor ctor oldtag m a
-> (e -> Ctor ctor oldtag m a)
-> Ctor ctor oldtag m a
catch_ Proxy# ctor
_ = forall b.
Coercible (m a -> (e -> m a) -> m a) b =>
(m a -> (e -> m a) -> m a) -> b
coerce @(m a -> (e -> m a) -> m a) ((m a -> (e -> m a) -> m a)
-> Ctor ctor oldtag m a
-> (e -> Ctor ctor oldtag m a)
-> Ctor ctor oldtag m a)
-> (m a -> (e -> m a) -> m a)
-> Ctor ctor oldtag m a
-> (e -> Ctor ctor oldtag m a)
-> Ctor ctor oldtag m a
forall a b. (a -> b) -> a -> b
$
forall k (tag :: k) e (m :: * -> *) a b.
HasCatch tag e m =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
forall (m :: * -> *) a b.
HasCatch oldtag sum m =>
(sum -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust @oldtag @sum ((sum -> Maybe e) -> m a -> (e -> m a) -> m a)
-> (sum -> Maybe e) -> m a -> (e -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ Getting (First e) sum e -> sum -> Maybe e
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview (forall a. AsConstructor' ctor sum a => Prism sum sum a a
forall (ctor :: Symbol) s a.
AsConstructor' ctor s a =>
Prism s s a a
Generic._Ctor' @ctor @sum)
{-# INLINE catch_ #-}
catchJust_ :: forall a b.
Proxy# ctor
-> (e -> Maybe b)
-> Ctor ctor oldtag m a
-> (b -> Ctor ctor oldtag m a)
-> Ctor ctor oldtag m a
catchJust_ :: Proxy# ctor
-> (e -> Maybe b)
-> Ctor ctor oldtag m a
-> (b -> Ctor ctor oldtag m a)
-> Ctor ctor oldtag m a
catchJust_ Proxy# ctor
_ = forall b.
Coercible ((e -> Maybe b) -> m a -> (b -> m a) -> m a) b =>
((e -> Maybe b) -> m a -> (b -> m a) -> m a) -> b
coerce @((e -> Maybe b) -> m a -> (b -> m a) -> m a) (((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> Ctor ctor oldtag m a
-> (b -> Ctor ctor oldtag m a)
-> Ctor ctor oldtag m a)
-> ((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> Ctor ctor oldtag m a
-> (b -> Ctor ctor oldtag m a)
-> Ctor ctor oldtag m a
forall a b. (a -> b) -> a -> b
$ \e -> Maybe b
f ->
forall k (tag :: k) e (m :: * -> *) a b.
HasCatch tag e m =>
(e -> Maybe b) -> m a -> (b -> m a) -> m a
forall (m :: * -> *) a b.
HasCatch oldtag sum m =>
(sum -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust @oldtag @sum ((sum -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (sum -> Maybe b) -> m a -> (b -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ e -> Maybe b
f (e -> Maybe b) -> (sum -> Maybe e) -> sum -> Maybe b
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Getting (First e) sum e -> sum -> Maybe e
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview (forall a. AsConstructor' ctor sum a => Prism sum sum a a
forall (ctor :: Symbol) s a.
AsConstructor' ctor s a =>
Prism s s a a
Generic._Ctor' @ctor @sum)
{-# INLINE catchJust_ #-}
instance
( HasThrow tag e m, MonadTrans t, Monad (t m) )
=> HasThrow tag e (Lift (t m))
where
throw_ :: forall a. Proxy# tag -> e -> Lift (t m) a
throw_ :: Proxy# tag -> e -> Lift (t m) a
throw_ Proxy# tag
tag = forall b. Coercible (e -> t m a) b => (e -> t m a) -> b
coerce @(e -> t m a) ((e -> t m a) -> e -> Lift (t m) a)
-> (e -> t m a) -> e -> Lift (t m) a
forall a b. (a -> b) -> a -> b
$ m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> t m a) -> (e -> m a) -> e -> t m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy# tag -> e -> m a
forall k (tag :: k) e (m :: * -> *) a.
HasThrow tag e m =>
Proxy# tag -> e -> m a
throw_ Proxy# tag
tag
{-# INLINE throw_ #-}
instance
( HasCatch tag e m, MonadTransControl t, Monad (t m) )
=> HasCatch tag e (Lift (t m))
where
catch_ :: forall a.
Proxy# tag
-> Lift (t m) a
-> (e -> Lift (t m) a)
-> Lift (t m) a
catch_ :: Proxy# tag -> Lift (t m) a -> (e -> Lift (t m) a) -> Lift (t m) a
catch_ Proxy# tag
tag = forall b.
Coercible (t m a -> (e -> t m a) -> t m a) b =>
(t m a -> (e -> t m a) -> t m a) -> b
coerce @(t m a -> (e -> t m a) -> t m a) ((t m a -> (e -> t m a) -> t m a)
-> Lift (t m) a -> (e -> Lift (t m) a) -> Lift (t m) a)
-> (t m a -> (e -> t m a) -> t m a)
-> Lift (t m) a
-> (e -> Lift (t m) a)
-> Lift (t m) a
forall a b. (a -> b) -> a -> b
$ \t m a
m e -> t m a
h ->
(Run t -> m (StT t a)) -> t m (StT t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith (\Run t
run -> Proxy# tag -> m (StT t a) -> (e -> m (StT t a)) -> m (StT t a)
forall k (tag :: k) e (m :: * -> *) a.
HasCatch tag e m =>
Proxy# tag -> m a -> (e -> m a) -> m a
catch_ Proxy# tag
tag (t m a -> m (StT t a)
Run t
run t m a
m) (t m a -> m (StT t a)
Run t
run (t m a -> m (StT t a)) -> (e -> t m a) -> e -> m (StT t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> t m a
h)) t m (StT t a) -> (StT t a -> t m a) -> t m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m (StT t a) -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT (m (StT t a) -> t m a)
-> (StT t a -> m (StT t a)) -> StT t a -> t m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StT t a -> m (StT t a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE catch_ #-}
catchJust_ :: forall a b.
Proxy# tag
-> (e -> Maybe b)
-> Lift (t m) a
-> (b -> Lift (t m) a)
-> Lift (t m) a
catchJust_ :: Proxy# tag
-> (e -> Maybe b)
-> Lift (t m) a
-> (b -> Lift (t m) a)
-> Lift (t m) a
catchJust_ Proxy# tag
tag =
forall b.
Coercible ((e -> Maybe b) -> t m a -> (b -> t m a) -> t m a) b =>
((e -> Maybe b) -> t m a -> (b -> t m a) -> t m a) -> b
coerce @((e -> Maybe b) -> t m a -> (b -> t m a) -> t m a) (((e -> Maybe b) -> t m a -> (b -> t m a) -> t m a)
-> (e -> Maybe b)
-> Lift (t m) a
-> (b -> Lift (t m) a)
-> Lift (t m) a)
-> ((e -> Maybe b) -> t m a -> (b -> t m a) -> t m a)
-> (e -> Maybe b)
-> Lift (t m) a
-> (b -> Lift (t m) a)
-> Lift (t m) a
forall a b. (a -> b) -> a -> b
$ \e -> Maybe b
f t m a
m b -> t m a
h ->
(Run t -> m (StT t a)) -> t m (StT t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith (\Run t
run -> Proxy# tag
-> (e -> Maybe b)
-> m (StT t a)
-> (b -> m (StT t a))
-> m (StT t a)
forall k (tag :: k) e (m :: * -> *) b a.
HasCatch tag e m =>
Proxy# tag -> (e -> Maybe b) -> m a -> (b -> m a) -> m a
catchJust_ Proxy# tag
tag e -> Maybe b
f (t m a -> m (StT t a)
Run t
run t m a
m) (t m a -> m (StT t a)
Run t
run (t m a -> m (StT t a)) -> (b -> t m a) -> b -> m (StT t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> t m a
h)) t m (StT t a) -> (StT t a -> t m a) -> t m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m (StT t a) -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT (m (StT t a) -> t m a)
-> (StT t a -> m (StT t a)) -> StT t a -> t m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StT t a -> m (StT t a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE catchJust_ #-}
deriving via ((t2 :: (Type -> Type) -> Type -> Type) ((t1 :: (Type -> Type) -> Type -> Type) m))
instance
( forall x. Coercible (m x) (t2 (t1 m) x)
, Monad m, HasThrow tag e (t2 (t1 m)) )
=> HasThrow tag e ((t2 :.: t1) m)
deriving via ((t2 :: (Type -> Type) -> Type -> Type) ((t1 :: (Type -> Type) -> Type -> Type) m))
instance
( forall x. Coercible (m x) (t2 (t1 m) x)
, Monad m, HasCatch tag e (t2 (t1 m)) )
=> HasCatch tag e ((t2 :.: t1) m)
type HasThrow' (tag :: k) = HasThrow tag (TypeOf k tag)
type HasCatch' (tag :: k) = HasCatch tag (TypeOf k tag)
data instance Reified tag (HasThrow tag e) m = ReifiedThrow {Reified tag (HasThrow tag e) m -> forall a. e -> m a
_throw :: forall a. e -> m a}
data instance Reified tag (HasCatch tag e) m = ReifiedCatch
{ Reified tag (HasCatch tag e) m -> Reified tag (HasThrow tag e) m
_catchThrow :: Reified tag (HasThrow tag e) m,
Reified tag (HasCatch tag e) m
-> forall a. m a -> (e -> m a) -> m a
_catch :: forall a. m a -> (e -> m a) -> m a,
Reified tag (HasCatch tag e) m
-> forall a b. (e -> Maybe b) -> m a -> (b -> m a) -> m a
_catchJust :: forall a b. (e -> Maybe b) -> m a -> (b -> m a) -> m a
}
instance
( Monad m,
Reifies s (Reified tag (HasThrow tag e) m)
) =>
HasThrow tag e (Reflected s (HasThrow tag e) m)
where
throw_ :: forall a. Proxy# tag -> e -> Reflected s (HasThrow tag e) m a
throw_ :: Proxy# tag -> e -> Reflected s (HasThrow tag e) m a
throw_ Proxy# tag
_ = forall b. Coercible (e -> m a) b => (e -> m a) -> b
coerce @(e -> m a) ((e -> m a) -> e -> Reflected s (HasThrow tag e) m a)
-> (e -> m a) -> e -> Reflected s (HasThrow tag e) m a
forall a b. (a -> b) -> a -> b
$ Reified tag (HasThrow tag e) m -> forall a. e -> m a
forall k (tag :: k) e (m :: * -> *).
Reified tag (HasThrow tag e) m -> forall a. e -> m a
_throw (Reified tag (HasThrow tag e) m -> forall a. e -> m a)
-> Reified tag (HasThrow tag e) m -> forall a. e -> m a
forall a b. (a -> b) -> a -> b
$ forall (tag :: k) (c :: (* -> *) -> Constraint) (m :: * -> *).
Reifies s (Reified tag c m) =>
Reified tag c m
forall k1 k2 (s :: k1) (tag :: k2) (c :: (* -> *) -> Constraint)
(m :: * -> *).
Reifies s (Reified tag c m) =>
Reified tag c m
reified @s
{-# INLINE throw_ #-}
instance
( Monad m,
Reifies s (Reified tag (HasCatch tag e) m)
) =>
HasThrow tag e (Reflected s (HasCatch tag e) m)
where
throw_ :: forall a. Proxy# tag -> e -> Reflected s (HasCatch tag e) m a
throw_ :: Proxy# tag -> e -> Reflected s (HasCatch tag e) m a
throw_ Proxy# tag
_ = forall b. Coercible (e -> m a) b => (e -> m a) -> b
coerce @(e -> m a) ((e -> m a) -> e -> Reflected s (HasCatch tag e) m a)
-> (e -> m a) -> e -> Reflected s (HasCatch tag e) m a
forall a b. (a -> b) -> a -> b
$ Reified tag (HasThrow tag e) m -> forall a. e -> m a
forall k (tag :: k) e (m :: * -> *).
Reified tag (HasThrow tag e) m -> forall a. e -> m a
_throw (Reified tag (HasThrow tag e) m -> forall a. e -> m a)
-> Reified tag (HasThrow tag e) m -> forall a. e -> m a
forall a b. (a -> b) -> a -> b
$ Reified tag (HasCatch tag e) m -> Reified tag (HasThrow tag e) m
forall k (tag :: k) e (m :: * -> *).
Reified tag (HasCatch tag e) m -> Reified tag (HasThrow tag e) m
_catchThrow (Reified tag (HasCatch tag e) m -> Reified tag (HasThrow tag e) m)
-> Reified tag (HasCatch tag e) m -> Reified tag (HasThrow tag e) m
forall a b. (a -> b) -> a -> b
$ forall (tag :: k) (c :: (* -> *) -> Constraint) (m :: * -> *).
Reifies s (Reified tag c m) =>
Reified tag c m
forall k1 k2 (s :: k1) (tag :: k2) (c :: (* -> *) -> Constraint)
(m :: * -> *).
Reifies s (Reified tag c m) =>
Reified tag c m
reified @s
{-# INLINE throw_ #-}
instance
( Monad m,
Reifies s (Reified tag (HasCatch tag e) m)
) =>
HasCatch tag e (Reflected s (HasCatch tag e) m)
where
catch_ :: forall a. Proxy# tag -> Reflected s (HasCatch tag e) m a -> (e -> Reflected s (HasCatch tag e) m a) -> Reflected s (HasCatch tag e) m a
catch_ :: Proxy# tag
-> Reflected s (HasCatch tag e) m a
-> (e -> Reflected s (HasCatch tag e) m a)
-> Reflected s (HasCatch tag e) m a
catch_ Proxy# tag
_ = forall b.
Coercible (m a -> (e -> m a) -> m a) b =>
(m a -> (e -> m a) -> m a) -> b
coerce @(m a -> (e -> m a) -> m a) ((m a -> (e -> m a) -> m a)
-> Reflected s (HasCatch tag e) m a
-> (e -> Reflected s (HasCatch tag e) m a)
-> Reflected s (HasCatch tag e) m a)
-> (m a -> (e -> m a) -> m a)
-> Reflected s (HasCatch tag e) m a
-> (e -> Reflected s (HasCatch tag e) m a)
-> Reflected s (HasCatch tag e) m a
forall a b. (a -> b) -> a -> b
$ Reified tag (HasCatch tag e) m
-> forall a. m a -> (e -> m a) -> m a
forall k (tag :: k) e (m :: * -> *).
Reified tag (HasCatch tag e) m
-> forall a. m a -> (e -> m a) -> m a
_catch (Reified tag (HasCatch tag e) m
-> forall a. m a -> (e -> m a) -> m a)
-> Reified tag (HasCatch tag e) m
-> forall a. m a -> (e -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ forall (tag :: k) (c :: (* -> *) -> Constraint) (m :: * -> *).
Reifies s (Reified tag c m) =>
Reified tag c m
forall k1 k2 (s :: k1) (tag :: k2) (c :: (* -> *) -> Constraint)
(m :: * -> *).
Reifies s (Reified tag c m) =>
Reified tag c m
reified @s
{-# INLINE catch_ #-}
catchJust_ :: forall a b. Proxy# tag -> (e -> Maybe b) -> Reflected s (HasCatch tag e) m a -> (b -> Reflected s (HasCatch tag e) m a) -> Reflected s (HasCatch tag e) m a
catchJust_ :: Proxy# tag
-> (e -> Maybe b)
-> Reflected s (HasCatch tag e) m a
-> (b -> Reflected s (HasCatch tag e) m a)
-> Reflected s (HasCatch tag e) m a
catchJust_ Proxy# tag
_ = forall b.
Coercible ((e -> Maybe b) -> m a -> (b -> m a) -> m a) b =>
((e -> Maybe b) -> m a -> (b -> m a) -> m a) -> b
coerce @((e -> Maybe b) -> m a -> (b -> m a) -> m a) (((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> Reflected s (HasCatch tag e) m a
-> (b -> Reflected s (HasCatch tag e) m a)
-> Reflected s (HasCatch tag e) m a)
-> ((e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> (e -> Maybe b)
-> Reflected s (HasCatch tag e) m a
-> (b -> Reflected s (HasCatch tag e) m a)
-> Reflected s (HasCatch tag e) m a
forall a b. (a -> b) -> a -> b
$ Reified tag (HasCatch tag e) m
-> forall a b. (e -> Maybe b) -> m a -> (b -> m a) -> m a
forall k (tag :: k) e (m :: * -> *).
Reified tag (HasCatch tag e) m
-> forall a b. (e -> Maybe b) -> m a -> (b -> m a) -> m a
_catchJust (Reified tag (HasCatch tag e) m
-> forall a b. (e -> Maybe b) -> m a -> (b -> m a) -> m a)
-> Reified tag (HasCatch tag e) m
-> forall a b. (e -> Maybe b) -> m a -> (b -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ forall (tag :: k) (c :: (* -> *) -> Constraint) (m :: * -> *).
Reifies s (Reified tag c m) =>
Reified tag c m
forall k1 k2 (s :: k1) (tag :: k2) (c :: (* -> *) -> Constraint)
(m :: * -> *).
Reifies s (Reified tag c m) =>
Reified tag c m
reified @s
{-# INLINE catchJust_ #-}