{-# LANGUAGE BlockArguments, DerivingVia #-}
module Control.Effect.Fail
  ( -- * Effects
    Fail(..)

    -- * Interpretations
  , runFail

  , failToThrow

  , failToNonDet

  , failToAlt

    -- * Simple variants of interpretations
  , failToThrowSimple

    -- * Threading constraints
  , ErrorThreads

    -- * Carriers
  , FailC
  , InterpretFailC(..)
  , InterpretFailReifiedC
  , FailToNonDetC
  , FailToAltC
  , InterpretFailSimpleC(..)
  ) where

import Data.Coerce

import Control.Applicative
import Control.Monad
import qualified Control.Monad.Fail as Fail

import Control.Effect
import Control.Effect.Error
import Control.Effect.NonDet
import Control.Effect.Type.Alt
import Control.Effect.Type.Fail

import Control.Effect.Carrier

-- Imports for coercion
import Control.Effect.Internal.Utils
import Control.Effect.Internal.Error
import Control.Effect.Carrier.Internal.Interpret
import Control.Effect.Carrier.Internal.Intro
import Control.Effect.Carrier.Internal.Compose
import Control.Monad.Trans.Except


-- | Like 'InterpretC' specialized to interpret 'Fail', but with a 'MonadFail'
-- instance based on the interpreted 'Fail'.
newtype InterpretFailC h m a = InterpretFailC {
    InterpretFailC h m a -> InterpretC h Fail m a
unInterpretFailC :: InterpretC h Fail m a
  }
  deriving ( a -> InterpretFailC h m b -> InterpretFailC h m a
(a -> b) -> InterpretFailC h m a -> InterpretFailC h m b
(forall a b.
 (a -> b) -> InterpretFailC h m a -> InterpretFailC h m b)
-> (forall a b. a -> InterpretFailC h m b -> InterpretFailC h m a)
-> Functor (InterpretFailC h m)
forall a b. a -> InterpretFailC h m b -> InterpretFailC h m a
forall a b.
(a -> b) -> InterpretFailC h m a -> InterpretFailC h m b
forall h (m :: * -> *) a b.
Functor m =>
a -> InterpretFailC h m b -> InterpretFailC h m a
forall h (m :: * -> *) a b.
Functor m =>
(a -> b) -> InterpretFailC h m a -> InterpretFailC h m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> InterpretFailC h m b -> InterpretFailC h m a
$c<$ :: forall h (m :: * -> *) a b.
Functor m =>
a -> InterpretFailC h m b -> InterpretFailC h m a
fmap :: (a -> b) -> InterpretFailC h m a -> InterpretFailC h m b
$cfmap :: forall h (m :: * -> *) a b.
Functor m =>
(a -> b) -> InterpretFailC h m a -> InterpretFailC h m b
Functor, Functor (InterpretFailC h m)
a -> InterpretFailC h m a
Functor (InterpretFailC h m)
-> (forall a. a -> InterpretFailC h m a)
-> (forall a b.
    InterpretFailC h m (a -> b)
    -> InterpretFailC h m a -> InterpretFailC h m b)
-> (forall a b c.
    (a -> b -> c)
    -> InterpretFailC h m a
    -> InterpretFailC h m b
    -> InterpretFailC h m c)
-> (forall a b.
    InterpretFailC h m a
    -> InterpretFailC h m b -> InterpretFailC h m b)
-> (forall a b.
    InterpretFailC h m a
    -> InterpretFailC h m b -> InterpretFailC h m a)
-> Applicative (InterpretFailC h m)
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m a
InterpretFailC h m (a -> b)
-> InterpretFailC h m a -> InterpretFailC h m b
(a -> b -> c)
-> InterpretFailC h m a
-> InterpretFailC h m b
-> InterpretFailC h m c
forall a. a -> InterpretFailC h m a
forall a b.
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m a
forall a b.
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
forall a b.
InterpretFailC h m (a -> b)
-> InterpretFailC h m a -> InterpretFailC h m b
forall a b c.
(a -> b -> c)
-> InterpretFailC h m a
-> InterpretFailC h m b
-> InterpretFailC h m c
forall h (m :: * -> *).
Applicative m =>
Functor (InterpretFailC h m)
forall h (m :: * -> *) a.
Applicative m =>
a -> InterpretFailC h m a
forall h (m :: * -> *) a b.
Applicative m =>
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m a
forall h (m :: * -> *) a b.
Applicative m =>
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
forall h (m :: * -> *) a b.
Applicative m =>
InterpretFailC h m (a -> b)
-> InterpretFailC h m a -> InterpretFailC h m b
forall h (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> InterpretFailC h m a
-> InterpretFailC h m b
-> InterpretFailC h 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
<* :: InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m a
$c<* :: forall h (m :: * -> *) a b.
Applicative m =>
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m a
*> :: InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
$c*> :: forall h (m :: * -> *) a b.
Applicative m =>
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
liftA2 :: (a -> b -> c)
-> InterpretFailC h m a
-> InterpretFailC h m b
-> InterpretFailC h m c
$cliftA2 :: forall h (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> InterpretFailC h m a
-> InterpretFailC h m b
-> InterpretFailC h m c
<*> :: InterpretFailC h m (a -> b)
-> InterpretFailC h m a -> InterpretFailC h m b
$c<*> :: forall h (m :: * -> *) a b.
Applicative m =>
InterpretFailC h m (a -> b)
-> InterpretFailC h m a -> InterpretFailC h m b
pure :: a -> InterpretFailC h m a
$cpure :: forall h (m :: * -> *) a.
Applicative m =>
a -> InterpretFailC h m a
$cp1Applicative :: forall h (m :: * -> *).
Applicative m =>
Functor (InterpretFailC h m)
Applicative, Applicative (InterpretFailC h m)
a -> InterpretFailC h m a
Applicative (InterpretFailC h m)
-> (forall a b.
    InterpretFailC h m a
    -> (a -> InterpretFailC h m b) -> InterpretFailC h m b)
-> (forall a b.
    InterpretFailC h m a
    -> InterpretFailC h m b -> InterpretFailC h m b)
-> (forall a. a -> InterpretFailC h m a)
-> Monad (InterpretFailC h m)
InterpretFailC h m a
-> (a -> InterpretFailC h m b) -> InterpretFailC h m b
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
forall a. a -> InterpretFailC h m a
forall a b.
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
forall a b.
InterpretFailC h m a
-> (a -> InterpretFailC h m b) -> InterpretFailC h m b
forall h (m :: * -> *). Monad m => Applicative (InterpretFailC h m)
forall h (m :: * -> *) a. Monad m => a -> InterpretFailC h m a
forall h (m :: * -> *) a b.
Monad m =>
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
forall h (m :: * -> *) a b.
Monad m =>
InterpretFailC h m a
-> (a -> InterpretFailC h m b) -> InterpretFailC h 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 -> InterpretFailC h m a
$creturn :: forall h (m :: * -> *) a. Monad m => a -> InterpretFailC h m a
>> :: InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
$c>> :: forall h (m :: * -> *) a b.
Monad m =>
InterpretFailC h m a
-> InterpretFailC h m b -> InterpretFailC h m b
>>= :: InterpretFailC h m a
-> (a -> InterpretFailC h m b) -> InterpretFailC h m b
$c>>= :: forall h (m :: * -> *) a b.
Monad m =>
InterpretFailC h m a
-> (a -> InterpretFailC h m b) -> InterpretFailC h m b
$cp1Monad :: forall h (m :: * -> *). Monad m => Applicative (InterpretFailC h m)
Monad
           , Applicative (InterpretFailC h m)
InterpretFailC h m a
Applicative (InterpretFailC h m)
-> (forall a. InterpretFailC h m a)
-> (forall a.
    InterpretFailC h m a
    -> InterpretFailC h m a -> InterpretFailC h m a)
-> (forall a. InterpretFailC h m a -> InterpretFailC h m [a])
-> (forall a. InterpretFailC h m a -> InterpretFailC h m [a])
-> Alternative (InterpretFailC h m)
InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
InterpretFailC h m a -> InterpretFailC h m [a]
InterpretFailC h m a -> InterpretFailC h m [a]
forall a. InterpretFailC h m a
forall a. InterpretFailC h m a -> InterpretFailC h m [a]
forall a.
InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
forall h (m :: * -> *).
Alternative m =>
Applicative (InterpretFailC h m)
forall h (m :: * -> *) a. Alternative m => InterpretFailC h m a
forall h (m :: * -> *) a.
Alternative m =>
InterpretFailC h m a -> InterpretFailC h m [a]
forall h (m :: * -> *) a.
Alternative m =>
InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h 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
many :: InterpretFailC h m a -> InterpretFailC h m [a]
$cmany :: forall h (m :: * -> *) a.
Alternative m =>
InterpretFailC h m a -> InterpretFailC h m [a]
some :: InterpretFailC h m a -> InterpretFailC h m [a]
$csome :: forall h (m :: * -> *) a.
Alternative m =>
InterpretFailC h m a -> InterpretFailC h m [a]
<|> :: InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
$c<|> :: forall h (m :: * -> *) a.
Alternative m =>
InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
empty :: InterpretFailC h m a
$cempty :: forall h (m :: * -> *) a. Alternative m => InterpretFailC h m a
$cp1Alternative :: forall h (m :: * -> *).
Alternative m =>
Applicative (InterpretFailC h m)
Alternative, Monad (InterpretFailC h m)
Alternative (InterpretFailC h m)
InterpretFailC h m a
Alternative (InterpretFailC h m)
-> Monad (InterpretFailC h m)
-> (forall a. InterpretFailC h m a)
-> (forall a.
    InterpretFailC h m a
    -> InterpretFailC h m a -> InterpretFailC h m a)
-> MonadPlus (InterpretFailC h m)
InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
forall a. InterpretFailC h m a
forall a.
InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
forall h (m :: * -> *). MonadPlus m => Monad (InterpretFailC h m)
forall h (m :: * -> *).
MonadPlus m =>
Alternative (InterpretFailC h m)
forall h (m :: * -> *) a. MonadPlus m => InterpretFailC h m a
forall h (m :: * -> *) a.
MonadPlus m =>
InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
$cmplus :: forall h (m :: * -> *) a.
MonadPlus m =>
InterpretFailC h m a
-> InterpretFailC h m a -> InterpretFailC h m a
mzero :: InterpretFailC h m a
$cmzero :: forall h (m :: * -> *) a. MonadPlus m => InterpretFailC h m a
$cp2MonadPlus :: forall h (m :: * -> *). MonadPlus m => Monad (InterpretFailC h m)
$cp1MonadPlus :: forall h (m :: * -> *).
MonadPlus m =>
Alternative (InterpretFailC h m)
MonadPlus
           , Monad (InterpretFailC h m)
Monad (InterpretFailC h m)
-> (forall a. (a -> InterpretFailC h m a) -> InterpretFailC h m a)
-> MonadFix (InterpretFailC h m)
(a -> InterpretFailC h m a) -> InterpretFailC h m a
forall a. (a -> InterpretFailC h m a) -> InterpretFailC h m a
forall h (m :: * -> *). MonadFix m => Monad (InterpretFailC h m)
forall h (m :: * -> *) a.
MonadFix m =>
(a -> InterpretFailC h m a) -> InterpretFailC h m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
mfix :: (a -> InterpretFailC h m a) -> InterpretFailC h m a
$cmfix :: forall h (m :: * -> *) a.
MonadFix m =>
(a -> InterpretFailC h m a) -> InterpretFailC h m a
$cp1MonadFix :: forall h (m :: * -> *). MonadFix m => Monad (InterpretFailC h m)
MonadFix, Monad (InterpretFailC h m)
Monad (InterpretFailC h m)
-> (forall a. IO a -> InterpretFailC h m a)
-> MonadIO (InterpretFailC h m)
IO a -> InterpretFailC h m a
forall a. IO a -> InterpretFailC h m a
forall h (m :: * -> *). MonadIO m => Monad (InterpretFailC h m)
forall h (m :: * -> *) a. MonadIO m => IO a -> InterpretFailC h m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> InterpretFailC h m a
$cliftIO :: forall h (m :: * -> *) a. MonadIO m => IO a -> InterpretFailC h m a
$cp1MonadIO :: forall h (m :: * -> *). MonadIO m => Monad (InterpretFailC h m)
MonadIO
           , Monad (InterpretFailC h m)
e -> InterpretFailC h m a
Monad (InterpretFailC h m)
-> (forall e a. Exception e => e -> InterpretFailC h m a)
-> MonadThrow (InterpretFailC h m)
forall e a. Exception e => e -> InterpretFailC h m a
forall h (m :: * -> *). MonadThrow m => Monad (InterpretFailC h m)
forall h (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> InterpretFailC h m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
throwM :: e -> InterpretFailC h m a
$cthrowM :: forall h (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> InterpretFailC h m a
$cp1MonadThrow :: forall h (m :: * -> *). MonadThrow m => Monad (InterpretFailC h m)
MonadThrow, MonadThrow (InterpretFailC h m)
MonadThrow (InterpretFailC h m)
-> (forall e a.
    Exception e =>
    InterpretFailC h m a
    -> (e -> InterpretFailC h m a) -> InterpretFailC h m a)
-> MonadCatch (InterpretFailC h m)
InterpretFailC h m a
-> (e -> InterpretFailC h m a) -> InterpretFailC h m a
forall e a.
Exception e =>
InterpretFailC h m a
-> (e -> InterpretFailC h m a) -> InterpretFailC h m a
forall h (m :: * -> *).
MonadCatch m =>
MonadThrow (InterpretFailC h m)
forall h (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
InterpretFailC h m a
-> (e -> InterpretFailC h m a) -> InterpretFailC h m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
catch :: InterpretFailC h m a
-> (e -> InterpretFailC h m a) -> InterpretFailC h m a
$ccatch :: forall h (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
InterpretFailC h m a
-> (e -> InterpretFailC h m a) -> InterpretFailC h m a
$cp1MonadCatch :: forall h (m :: * -> *).
MonadCatch m =>
MonadThrow (InterpretFailC h m)
MonadCatch, MonadCatch (InterpretFailC h m)
MonadCatch (InterpretFailC h m)
-> (forall b.
    ((forall a. InterpretFailC h m a -> InterpretFailC h m a)
     -> InterpretFailC h m b)
    -> InterpretFailC h m b)
-> (forall b.
    ((forall a. InterpretFailC h m a -> InterpretFailC h m a)
     -> InterpretFailC h m b)
    -> InterpretFailC h m b)
-> (forall a b c.
    InterpretFailC h m a
    -> (a -> ExitCase b -> InterpretFailC h m c)
    -> (a -> InterpretFailC h m b)
    -> InterpretFailC h m (b, c))
-> MonadMask (InterpretFailC h m)
InterpretFailC h m a
-> (a -> ExitCase b -> InterpretFailC h m c)
-> (a -> InterpretFailC h m b)
-> InterpretFailC h m (b, c)
((forall a. InterpretFailC h m a -> InterpretFailC h m a)
 -> InterpretFailC h m b)
-> InterpretFailC h m b
((forall a. InterpretFailC h m a -> InterpretFailC h m a)
 -> InterpretFailC h m b)
-> InterpretFailC h m b
forall b.
((forall a. InterpretFailC h m a -> InterpretFailC h m a)
 -> InterpretFailC h m b)
-> InterpretFailC h m b
forall a b c.
InterpretFailC h m a
-> (a -> ExitCase b -> InterpretFailC h m c)
-> (a -> InterpretFailC h m b)
-> InterpretFailC h m (b, c)
forall h (m :: * -> *).
MonadMask m =>
MonadCatch (InterpretFailC h m)
forall h (m :: * -> *) b.
MonadMask m =>
((forall a. InterpretFailC h m a -> InterpretFailC h m a)
 -> InterpretFailC h m b)
-> InterpretFailC h m b
forall h (m :: * -> *) a b c.
MonadMask m =>
InterpretFailC h m a
-> (a -> ExitCase b -> InterpretFailC h m c)
-> (a -> InterpretFailC h m b)
-> InterpretFailC h m (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
generalBracket :: InterpretFailC h m a
-> (a -> ExitCase b -> InterpretFailC h m c)
-> (a -> InterpretFailC h m b)
-> InterpretFailC h m (b, c)
$cgeneralBracket :: forall h (m :: * -> *) a b c.
MonadMask m =>
InterpretFailC h m a
-> (a -> ExitCase b -> InterpretFailC h m c)
-> (a -> InterpretFailC h m b)
-> InterpretFailC h m (b, c)
uninterruptibleMask :: ((forall a. InterpretFailC h m a -> InterpretFailC h m a)
 -> InterpretFailC h m b)
-> InterpretFailC h m b
$cuninterruptibleMask :: forall h (m :: * -> *) b.
MonadMask m =>
((forall a. InterpretFailC h m a -> InterpretFailC h m a)
 -> InterpretFailC h m b)
-> InterpretFailC h m b
mask :: ((forall a. InterpretFailC h m a -> InterpretFailC h m a)
 -> InterpretFailC h m b)
-> InterpretFailC h m b
$cmask :: forall h (m :: * -> *) b.
MonadMask m =>
((forall a. InterpretFailC h m a -> InterpretFailC h m a)
 -> InterpretFailC h m b)
-> InterpretFailC h m b
$cp1MonadMask :: forall h (m :: * -> *).
MonadMask m =>
MonadCatch (InterpretFailC h m)
MonadMask
           , MonadBase b, MonadBaseControl b
           )
  deriving (m a -> InterpretFailC h m a
(forall (m :: * -> *) a. Monad m => m a -> InterpretFailC h m a)
-> MonadTrans (InterpretFailC h)
forall h (m :: * -> *) a. Monad m => m a -> InterpretFailC h m a
forall (m :: * -> *) a. Monad m => m a -> InterpretFailC h m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> InterpretFailC h m a
$clift :: forall h (m :: * -> *) a. Monad m => m a -> InterpretFailC h m a
MonadTrans, MonadTrans (InterpretFailC h)
m (StT (InterpretFailC h) a) -> InterpretFailC h m a
MonadTrans (InterpretFailC h)
-> (forall (m :: * -> *) a.
    Monad m =>
    (Run (InterpretFailC h) -> m a) -> InterpretFailC h m a)
-> (forall (m :: * -> *) a.
    Monad m =>
    m (StT (InterpretFailC h) a) -> InterpretFailC h m a)
-> MonadTransControl (InterpretFailC h)
(Run (InterpretFailC h) -> m a) -> InterpretFailC h m a
forall h. MonadTrans (InterpretFailC h)
forall h (m :: * -> *) a.
Monad m =>
m (StT (InterpretFailC h) a) -> InterpretFailC h m a
forall h (m :: * -> *) a.
Monad m =>
(Run (InterpretFailC h) -> m a) -> InterpretFailC h m a
forall (m :: * -> *) a.
Monad m =>
m (StT (InterpretFailC h) a) -> InterpretFailC h m a
forall (m :: * -> *) a.
Monad m =>
(Run (InterpretFailC h) -> m a) -> InterpretFailC h m a
forall (t :: (* -> *) -> * -> *).
MonadTrans t
-> (forall (m :: * -> *) a. Monad m => (Run t -> m a) -> t m a)
-> (forall (m :: * -> *) a. Monad m => m (StT t a) -> t m a)
-> MonadTransControl t
restoreT :: m (StT (InterpretFailC h) a) -> InterpretFailC h m a
$crestoreT :: forall h (m :: * -> *) a.
Monad m =>
m (StT (InterpretFailC h) a) -> InterpretFailC h m a
liftWith :: (Run (InterpretFailC h) -> m a) -> InterpretFailC h m a
$cliftWith :: forall h (m :: * -> *) a.
Monad m =>
(Run (InterpretFailC h) -> m a) -> InterpretFailC h m a
$cp1MonadTransControl :: forall h. MonadTrans (InterpretFailC h)
MonadTransControl) via IdentityT

type InterpretFailReifiedC m a
   = forall s
   . ReifiesHandler s Fail m
  => InterpretFailC (ViaReifiedH s) m a

deriving via InterpretC h Fail m instance
  Handler h Fail m => Carrier (InterpretFailC h m)

deriving via Effly (InterpretFailC h m)
    instance Handler h Fail m
          => MonadFail (InterpretFailC h m)

-- | Transform a 'Fail' effect to a 'Throw' effect by providing a function
-- to transform a pattern match failure into an exception.
--
-- You can use this in application code to locally get access to a 'MonadFail'
-- instance (since 'InterpretFailReifiedC' has a 'MonadFail' instance based
-- on the 'Fail' effect this interprets).
--
-- For example:
--
-- @
--   'failToThrow' (\\_ -> 'throw' exc) (do { Just a <- pure Nothing; return a})
-- = 'throw' exc
-- @
--
-- This has a higher-rank type, as it makes use of 'InterpretFailReifiedC'.
-- __This makes 'failToThrow' very difficult to use partially applied.__
-- __In particular, it can't be composed using @'.'@.__
--
-- If performance is secondary, consider using the slower 'failToThrowSimple',
-- which doesn't have a higher-rank type. __However__, you typically don't
-- want to use 'failToThrowSimple' in application code, since 'failToThrowSimple'
-- emits a 'ReaderThreads' threading constraint (see 'Threaders').
failToThrow :: Eff (Throw e) m
            => (String -> e)
            -> InterpretFailReifiedC m a
            -> m a
failToThrow :: (String -> e) -> InterpretFailReifiedC m a -> m a
failToThrow String -> e
f InterpretFailReifiedC m a
m =
    EffHandler Fail m -> InterpretReifiedC Fail m a -> m a
forall (e :: (* -> *) -> * -> *) (m :: * -> *) a.
(RepresentationalEff e, Carrier m) =>
EffHandler e m -> InterpretReifiedC e m a -> m a
interpret \case
      Fail s -> e -> Effly z x
forall e (m :: * -> *) a. Eff (Throw e) m => e -> m a
throw (String -> e
f String
s)
  (InterpretReifiedC Fail m a -> m a)
-> InterpretReifiedC Fail m a -> m a
forall a b. (a -> b) -> a -> b
$ InterpretFailC (ViaReifiedH s) m a
-> InterpretC (ViaReifiedH s) Fail m a
forall h (m :: * -> *) a.
InterpretFailC h m a -> InterpretC h Fail m a
unInterpretFailC
  (InterpretFailC (ViaReifiedH s) m a
 -> InterpretC (ViaReifiedH s) Fail m a)
-> InterpretFailC (ViaReifiedH s) m a
-> InterpretC (ViaReifiedH s) Fail m a
forall a b. (a -> b) -> a -> b
$ InterpretFailC (ViaReifiedH s) m a
InterpretFailReifiedC m a
m
{-# INLINE failToThrow #-}

data FailToAltH

type FailToAltC = InterpretFailC FailToAltH

instance Eff Alt m => Handler FailToAltH Fail m where
  effHandler :: Fail (Effly z) x -> Effly z x
effHandler Fail (Effly z) x
_ = Effly (Effly z) x -> Effly z x
forall k (m :: k -> *) (a :: k). Effly m a -> m a
runEffly Effly (Effly z) x
forall (f :: * -> *) a. Alternative f => f a
empty
  {-# INLINEABLE effHandler #-}

data FailToNonDetH

instance Eff NonDet m => Handler FailToNonDetH Fail m where
  effHandler :: Fail (Effly z) x -> Effly z x
effHandler Fail (Effly z) x
_ = Effly z x
forall (m :: * -> *) a. Eff NonDet m => m a
lose
  {-# INLINEABLE effHandler #-}

type FailToNonDetC = InterpretFailC FailToNonDetH

-- | Transform a 'Fail' effect to an 'Alt' effect by having a
-- pattern match failure be 'empty'.
--
-- You can use this in application code to locally get access to a 'MonadFail'
-- instance (since 'FailToAltC' has a 'MonadFail' instance based
-- on the 'Fail' effect this interprets).
failToAlt :: Eff Alt m
          => FailToAltC m a
          -> m a
failToAlt :: FailToAltC m a -> m a
failToAlt = InterpretC FailToAltH Fail m a -> m a
forall h (e :: (* -> *) -> * -> *) (m :: * -> *) a.
Handler h e m =>
InterpretC h e m a -> m a
interpretViaHandler (InterpretC FailToAltH Fail m a -> m a)
-> (FailToAltC m a -> InterpretC FailToAltH Fail m a)
-> FailToAltC m a
-> m a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# FailToAltC m a -> InterpretC FailToAltH Fail m a
forall h (m :: * -> *) a.
InterpretFailC h m a -> InterpretC h Fail m a
unInterpretFailC
{-# INLINE failToAlt #-}

-- | Transform a 'Fail' effect to a 'NonDet' effect by having a
-- pattern match failure be 'lose'.
--
-- You can use this in application code to locally get access to a 'MonadFail'
-- instance (since 'FailToNonDetC' has a 'MonadFail' instance based
-- on the 'Fail' effect this interprets).
--
-- For example:
--
-- @
--   'failToNonDet' (do { Just a <- pure Nothing; return a})
-- = 'lose'
-- @
failToNonDet :: Eff NonDet m
             => FailToNonDetC m a
             -> m a
failToNonDet :: FailToNonDetC m a -> m a
failToNonDet = InterpretC FailToNonDetH Fail m a -> m a
forall h (e :: (* -> *) -> * -> *) (m :: * -> *) a.
Handler h e m =>
InterpretC h e m a -> m a
interpretViaHandler (InterpretC FailToNonDetH Fail m a -> m a)
-> (FailToNonDetC m a -> InterpretC FailToNonDetH Fail m a)
-> FailToNonDetC m a
-> m a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# FailToNonDetC m a -> InterpretC FailToNonDetH Fail m a
forall h (m :: * -> *) a.
InterpretFailC h m a -> InterpretC h Fail m a
unInterpretFailC
{-# INLINE failToNonDet #-}

data FailH

newtype FailC m a = FailC {
    FailC m a
-> ReinterpretC FailH Fail '[Throw String] (ThrowC String m) a
unFailC ::
        ReinterpretC FailH Fail '[Throw String]
      ( ThrowC String
      ( m
      )) a
  } deriving ( a -> FailC m b -> FailC m a
(a -> b) -> FailC m a -> FailC m b
(forall a b. (a -> b) -> FailC m a -> FailC m b)
-> (forall a b. a -> FailC m b -> FailC m a) -> Functor (FailC m)
forall a b. a -> FailC m b -> FailC m a
forall a b. (a -> b) -> FailC m a -> FailC m b
forall (m :: * -> *) a b. Functor m => a -> FailC m b -> FailC m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> FailC m a -> FailC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> FailC m b -> FailC m a
$c<$ :: forall (m :: * -> *) a b. Functor m => a -> FailC m b -> FailC m a
fmap :: (a -> b) -> FailC m a -> FailC m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> FailC m a -> FailC m b
Functor, Functor (FailC m)
a -> FailC m a
Functor (FailC m)
-> (forall a. a -> FailC m a)
-> (forall a b. FailC m (a -> b) -> FailC m a -> FailC m b)
-> (forall a b c.
    (a -> b -> c) -> FailC m a -> FailC m b -> FailC m c)
-> (forall a b. FailC m a -> FailC m b -> FailC m b)
-> (forall a b. FailC m a -> FailC m b -> FailC m a)
-> Applicative (FailC m)
FailC m a -> FailC m b -> FailC m b
FailC m a -> FailC m b -> FailC m a
FailC m (a -> b) -> FailC m a -> FailC m b
(a -> b -> c) -> FailC m a -> FailC m b -> FailC m c
forall a. a -> FailC m a
forall a b. FailC m a -> FailC m b -> FailC m a
forall a b. FailC m a -> FailC m b -> FailC m b
forall a b. FailC m (a -> b) -> FailC m a -> FailC m b
forall a b c. (a -> b -> c) -> FailC m a -> FailC m b -> FailC m c
forall (m :: * -> *). Monad m => Functor (FailC m)
forall (m :: * -> *) a. Monad m => a -> FailC m a
forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m a
forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m b
forall (m :: * -> *) a b.
Monad m =>
FailC m (a -> b) -> FailC m a -> FailC m b
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> FailC m a -> FailC m b -> FailC 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
<* :: FailC m a -> FailC m b -> FailC m a
$c<* :: forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m a
*> :: FailC m a -> FailC m b -> FailC m b
$c*> :: forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m b
liftA2 :: (a -> b -> c) -> FailC m a -> FailC m b -> FailC m c
$cliftA2 :: forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> FailC m a -> FailC m b -> FailC m c
<*> :: FailC m (a -> b) -> FailC m a -> FailC m b
$c<*> :: forall (m :: * -> *) a b.
Monad m =>
FailC m (a -> b) -> FailC m a -> FailC m b
pure :: a -> FailC m a
$cpure :: forall (m :: * -> *) a. Monad m => a -> FailC m a
$cp1Applicative :: forall (m :: * -> *). Monad m => Functor (FailC m)
Applicative, Applicative (FailC m)
a -> FailC m a
Applicative (FailC m)
-> (forall a b. FailC m a -> (a -> FailC m b) -> FailC m b)
-> (forall a b. FailC m a -> FailC m b -> FailC m b)
-> (forall a. a -> FailC m a)
-> Monad (FailC m)
FailC m a -> (a -> FailC m b) -> FailC m b
FailC m a -> FailC m b -> FailC m b
forall a. a -> FailC m a
forall a b. FailC m a -> FailC m b -> FailC m b
forall a b. FailC m a -> (a -> FailC m b) -> FailC m b
forall (m :: * -> *). Monad m => Applicative (FailC m)
forall (m :: * -> *) a. Monad m => a -> FailC m a
forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m b
forall (m :: * -> *) a b.
Monad m =>
FailC m a -> (a -> FailC m b) -> FailC 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 -> FailC m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> FailC m a
>> :: FailC m a -> FailC m b -> FailC m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
FailC m a -> FailC m b -> FailC m b
>>= :: FailC m a -> (a -> FailC m b) -> FailC m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
FailC m a -> (a -> FailC m b) -> FailC m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (FailC m)
Monad
             , Applicative (FailC m)
FailC m a
Applicative (FailC m)
-> (forall a. FailC m a)
-> (forall a. FailC m a -> FailC m a -> FailC m a)
-> (forall a. FailC m a -> FailC m [a])
-> (forall a. FailC m a -> FailC m [a])
-> Alternative (FailC m)
FailC m a -> FailC m a -> FailC m a
FailC m a -> FailC m [a]
FailC m a -> FailC m [a]
forall a. FailC m a
forall a. FailC m a -> FailC m [a]
forall a. FailC m a -> FailC m a -> FailC m a
forall (m :: * -> *). Monad m => Applicative (FailC m)
forall (m :: * -> *) a. Monad m => FailC m a
forall (m :: * -> *) a. Monad m => FailC m a -> FailC m [a]
forall (m :: * -> *) a.
Monad m =>
FailC m a -> FailC m a -> FailC 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
many :: FailC m a -> FailC m [a]
$cmany :: forall (m :: * -> *) a. Monad m => FailC m a -> FailC m [a]
some :: FailC m a -> FailC m [a]
$csome :: forall (m :: * -> *) a. Monad m => FailC m a -> FailC m [a]
<|> :: FailC m a -> FailC m a -> FailC m a
$c<|> :: forall (m :: * -> *) a.
Monad m =>
FailC m a -> FailC m a -> FailC m a
empty :: FailC m a
$cempty :: forall (m :: * -> *) a. Monad m => FailC m a
$cp1Alternative :: forall (m :: * -> *). Monad m => Applicative (FailC m)
Alternative, Monad (FailC m)
Alternative (FailC m)
FailC m a
Alternative (FailC m)
-> Monad (FailC m)
-> (forall a. FailC m a)
-> (forall a. FailC m a -> FailC m a -> FailC m a)
-> MonadPlus (FailC m)
FailC m a -> FailC m a -> FailC m a
forall a. FailC m a
forall a. FailC m a -> FailC m a -> FailC m a
forall (m :: * -> *). Monad m => Monad (FailC m)
forall (m :: * -> *). Monad m => Alternative (FailC m)
forall (m :: * -> *) a. Monad m => FailC m a
forall (m :: * -> *) a.
Monad m =>
FailC m a -> FailC m a -> FailC m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: FailC m a -> FailC m a -> FailC m a
$cmplus :: forall (m :: * -> *) a.
Monad m =>
FailC m a -> FailC m a -> FailC m a
mzero :: FailC m a
$cmzero :: forall (m :: * -> *) a. Monad m => FailC m a
$cp2MonadPlus :: forall (m :: * -> *). Monad m => Monad (FailC m)
$cp1MonadPlus :: forall (m :: * -> *). Monad m => Alternative (FailC m)
MonadPlus
             , Monad (FailC m)
Monad (FailC m)
-> (forall a. (a -> FailC m a) -> FailC m a) -> MonadFix (FailC m)
(a -> FailC m a) -> FailC m a
forall a. (a -> FailC m a) -> FailC m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (FailC m)
forall (m :: * -> *) a. MonadFix m => (a -> FailC m a) -> FailC m a
mfix :: (a -> FailC m a) -> FailC m a
$cmfix :: forall (m :: * -> *) a. MonadFix m => (a -> FailC m a) -> FailC m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (FailC m)
MonadFix, Monad (FailC m)
Monad (FailC m)
-> (forall a. IO a -> FailC m a) -> MonadIO (FailC m)
IO a -> FailC m a
forall a. IO a -> FailC m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (FailC m)
forall (m :: * -> *) a. MonadIO m => IO a -> FailC m a
liftIO :: IO a -> FailC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> FailC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (FailC m)
MonadIO
             , Monad (FailC m)
e -> FailC m a
Monad (FailC m)
-> (forall e a. Exception e => e -> FailC m a)
-> MonadThrow (FailC m)
forall e a. Exception e => e -> FailC m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (FailC m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> FailC m a
throwM :: e -> FailC m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> FailC m a
$cp1MonadThrow :: forall (m :: * -> *). MonadThrow m => Monad (FailC m)
MonadThrow, MonadThrow (FailC m)
MonadThrow (FailC m)
-> (forall e a.
    Exception e =>
    FailC m a -> (e -> FailC m a) -> FailC m a)
-> MonadCatch (FailC m)
FailC m a -> (e -> FailC m a) -> FailC m a
forall e a.
Exception e =>
FailC m a -> (e -> FailC m a) -> FailC m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *). MonadCatch m => MonadThrow (FailC m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
FailC m a -> (e -> FailC m a) -> FailC m a
catch :: FailC m a -> (e -> FailC m a) -> FailC m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
FailC m a -> (e -> FailC m a) -> FailC m a
$cp1MonadCatch :: forall (m :: * -> *). MonadCatch m => MonadThrow (FailC m)
MonadCatch, MonadCatch (FailC m)
MonadCatch (FailC m)
-> (forall b.
    ((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b)
-> (forall b.
    ((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b)
-> (forall a b c.
    FailC m a
    -> (a -> ExitCase b -> FailC m c)
    -> (a -> FailC m b)
    -> FailC m (b, c))
-> MonadMask (FailC m)
FailC m a
-> (a -> ExitCase b -> FailC m c)
-> (a -> FailC m b)
-> FailC m (b, c)
((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b
((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b
forall b.
((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b
forall a b c.
FailC m a
-> (a -> ExitCase b -> FailC m c)
-> (a -> FailC m b)
-> FailC m (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
forall (m :: * -> *). MonadMask m => MonadCatch (FailC m)
forall (m :: * -> *) b.
MonadMask m =>
((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b
forall (m :: * -> *) a b c.
MonadMask m =>
FailC m a
-> (a -> ExitCase b -> FailC m c)
-> (a -> FailC m b)
-> FailC m (b, c)
generalBracket :: FailC m a
-> (a -> ExitCase b -> FailC m c)
-> (a -> FailC m b)
-> FailC m (b, c)
$cgeneralBracket :: forall (m :: * -> *) a b c.
MonadMask m =>
FailC m a
-> (a -> ExitCase b -> FailC m c)
-> (a -> FailC m b)
-> FailC m (b, c)
uninterruptibleMask :: ((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b
$cuninterruptibleMask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b
mask :: ((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b
$cmask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. FailC m a -> FailC m a) -> FailC m b) -> FailC m b
$cp1MonadMask :: forall (m :: * -> *). MonadMask m => MonadCatch (FailC m)
MonadMask
             , MonadBase b, MonadBaseControl b
             )
    deriving (m a -> FailC m a
(forall (m :: * -> *) a. Monad m => m a -> FailC m a)
-> MonadTrans FailC
forall (m :: * -> *) a. Monad m => m a -> FailC m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> FailC m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> FailC m a
MonadTrans, MonadTrans FailC
m (StT FailC a) -> FailC m a
MonadTrans FailC
-> (forall (m :: * -> *) a.
    Monad m =>
    (Run FailC -> m a) -> FailC m a)
-> (forall (m :: * -> *) a.
    Monad m =>
    m (StT FailC a) -> FailC m a)
-> MonadTransControl FailC
(Run FailC -> m a) -> FailC m a
forall (m :: * -> *) a. Monad m => m (StT FailC a) -> FailC m a
forall (m :: * -> *) a. Monad m => (Run FailC -> m a) -> FailC m a
forall (t :: (* -> *) -> * -> *).
MonadTrans t
-> (forall (m :: * -> *) a. Monad m => (Run t -> m a) -> t m a)
-> (forall (m :: * -> *) a. Monad m => m (StT t a) -> t m a)
-> MonadTransControl t
restoreT :: m (StT FailC a) -> FailC m a
$crestoreT :: forall (m :: * -> *) a. Monad m => m (StT FailC a) -> FailC m a
liftWith :: (Run FailC -> m a) -> FailC m a
$cliftWith :: forall (m :: * -> *) a. Monad m => (Run FailC -> m a) -> FailC m a
$cp1MonadTransControl :: MonadTrans FailC
MonadTransControl)
    via CompositionBaseT
     '[ ReinterpretC FailH Fail '[Throw String]
      , ThrowC String
      ]

deriving via  Effly (FailC m)
    instance (Carrier m, Threads (ExceptT String) (Prims m))
          => MonadFail (FailC m)

deriving instance (Carrier m, Threads (ExceptT String) (Prims m))
               => Carrier (FailC m)

instance Eff (Throw String) m
      => Handler FailH Fail m where
  effHandler :: Fail (Effly z) x -> Effly z x
effHandler = forall e (m :: * -> *) a. Eff (Throw e) m => e -> m a
forall (m :: * -> *) a. Eff (Throw String) m => String -> m a
throw @String (String -> Effly z x)
-> (Fail (Effly z) x -> String) -> Fail (Effly z) x -> Effly z x
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# Fail (Effly z) x -> String
coerce
  {-# INLINEABLE effHandler #-}

-- | Run a 'Fail' effect purely, by returning @Left failureMessage@
-- upon a pattern match failure.
--
-- 'FailC' has an 'MonadFail' instance based on the 'Fail'
-- effect it interprets.
--
-- @'Derivs' ('FailC' m) = 'Fail' ': 'Derivs' m@
--
-- @'Control.Effect.Primitive.Prims'  ('FailC' m) = 'Control.Effect.Primitive.Prims' m@
runFail :: forall m a p
         . ( Threaders '[ErrorThreads] m p
           , Carrier m
           )
        => FailC m a
        -> m (Either String a)
runFail :: FailC m a -> m (Either String a)
runFail =
     ThrowC String m a -> m (Either String a)
forall e (m :: * -> *) a (p :: [(* -> *) -> * -> *]).
(Carrier m, Threaders '[ErrorThreads] m p) =>
ThrowC e m a -> m (Either e a)
runThrow
  (ThrowC String m a -> m (Either String a))
-> (ReinterpretC FailH Fail '[Throw String] (ThrowC String m) a
    -> ThrowC String m a)
-> ReinterpretC FailH Fail '[Throw String] (ThrowC String m) a
-> m (Either String a)
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# ReinterpretC FailH Fail '[Throw String] (ThrowC String m) a
-> ThrowC String m a
forall h (e :: (* -> *) -> * -> *) (new :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
(Handler h e m, KnownList new, HeadEffs new m) =>
ReinterpretC h e new m a -> m a
reinterpretViaHandler
  (ReinterpretC FailH Fail '[Throw String] (ThrowC String m) a
 -> m (Either String a))
-> (FailC m a
    -> ReinterpretC FailH Fail '[Throw String] (ThrowC String m) a)
-> FailC m a
-> m (Either String a)
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# FailC m a
-> ReinterpretC FailH Fail '[Throw String] (ThrowC String m) a
forall (m :: * -> *) a.
FailC m a
-> ReinterpretC FailH Fail '[Throw String] (ThrowC String m) a
unFailC

-- | Like 'InterpretSimpleC' specialized to interpret 'Fail', but with
-- a 'MonadFail' instance based on the interpreted 'Fail'.
newtype InterpretFailSimpleC m a = InterpretFailSimpleC {
    InterpretFailSimpleC m a -> InterpretSimpleC Fail m a
unInterpretFailSimpleC :: InterpretSimpleC Fail m a
  }
  deriving ( a -> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
(a -> b) -> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
(forall a b.
 (a -> b) -> InterpretFailSimpleC m a -> InterpretFailSimpleC m b)
-> (forall a b.
    a -> InterpretFailSimpleC m b -> InterpretFailSimpleC m a)
-> Functor (InterpretFailSimpleC m)
forall a b.
a -> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
forall a b.
(a -> b) -> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
forall (m :: * -> *) a b.
Functor m =>
a -> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
fmap :: (a -> b) -> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
Functor, Functor (InterpretFailSimpleC m)
a -> InterpretFailSimpleC m a
Functor (InterpretFailSimpleC m)
-> (forall a. a -> InterpretFailSimpleC m a)
-> (forall a b.
    InterpretFailSimpleC m (a -> b)
    -> InterpretFailSimpleC m a -> InterpretFailSimpleC m b)
-> (forall a b c.
    (a -> b -> c)
    -> InterpretFailSimpleC m a
    -> InterpretFailSimpleC m b
    -> InterpretFailSimpleC m c)
-> (forall a b.
    InterpretFailSimpleC m a
    -> InterpretFailSimpleC m b -> InterpretFailSimpleC m b)
-> (forall a b.
    InterpretFailSimpleC m a
    -> InterpretFailSimpleC m b -> InterpretFailSimpleC m a)
-> Applicative (InterpretFailSimpleC m)
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
InterpretFailSimpleC m (a -> b)
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
(a -> b -> c)
-> InterpretFailSimpleC m a
-> InterpretFailSimpleC m b
-> InterpretFailSimpleC m c
forall a. a -> InterpretFailSimpleC m a
forall a b.
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
forall a b.
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
forall a b.
InterpretFailSimpleC m (a -> b)
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
forall a b c.
(a -> b -> c)
-> InterpretFailSimpleC m a
-> InterpretFailSimpleC m b
-> InterpretFailSimpleC 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 (InterpretFailSimpleC m)
forall (m :: * -> *) a.
Applicative m =>
a -> InterpretFailSimpleC m a
forall (m :: * -> *) a b.
Applicative m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
forall (m :: * -> *) a b.
Applicative m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
forall (m :: * -> *) a b.
Applicative m =>
InterpretFailSimpleC m (a -> b)
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> InterpretFailSimpleC m a
-> InterpretFailSimpleC m b
-> InterpretFailSimpleC m c
<* :: InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m a
*> :: InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
liftA2 :: (a -> b -> c)
-> InterpretFailSimpleC m a
-> InterpretFailSimpleC m b
-> InterpretFailSimpleC m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> InterpretFailSimpleC m a
-> InterpretFailSimpleC m b
-> InterpretFailSimpleC m c
<*> :: InterpretFailSimpleC m (a -> b)
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
InterpretFailSimpleC m (a -> b)
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m b
pure :: a -> InterpretFailSimpleC m a
$cpure :: forall (m :: * -> *) a.
Applicative m =>
a -> InterpretFailSimpleC m a
$cp1Applicative :: forall (m :: * -> *).
Applicative m =>
Functor (InterpretFailSimpleC m)
Applicative, Applicative (InterpretFailSimpleC m)
a -> InterpretFailSimpleC m a
Applicative (InterpretFailSimpleC m)
-> (forall a b.
    InterpretFailSimpleC m a
    -> (a -> InterpretFailSimpleC m b) -> InterpretFailSimpleC m b)
-> (forall a b.
    InterpretFailSimpleC m a
    -> InterpretFailSimpleC m b -> InterpretFailSimpleC m b)
-> (forall a. a -> InterpretFailSimpleC m a)
-> Monad (InterpretFailSimpleC m)
InterpretFailSimpleC m a
-> (a -> InterpretFailSimpleC m b) -> InterpretFailSimpleC m b
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
forall a. a -> InterpretFailSimpleC m a
forall a b.
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
forall a b.
InterpretFailSimpleC m a
-> (a -> InterpretFailSimpleC m b) -> InterpretFailSimpleC m b
forall (m :: * -> *).
Monad m =>
Applicative (InterpretFailSimpleC m)
forall (m :: * -> *) a. Monad m => a -> InterpretFailSimpleC m a
forall (m :: * -> *) a b.
Monad m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
forall (m :: * -> *) a b.
Monad m =>
InterpretFailSimpleC m a
-> (a -> InterpretFailSimpleC m b) -> InterpretFailSimpleC 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 -> InterpretFailSimpleC m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> InterpretFailSimpleC m a
>> :: InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m b -> InterpretFailSimpleC m b
>>= :: InterpretFailSimpleC m a
-> (a -> InterpretFailSimpleC m b) -> InterpretFailSimpleC m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
InterpretFailSimpleC m a
-> (a -> InterpretFailSimpleC m b) -> InterpretFailSimpleC m b
$cp1Monad :: forall (m :: * -> *).
Monad m =>
Applicative (InterpretFailSimpleC m)
Monad
           , Applicative (InterpretFailSimpleC m)
InterpretFailSimpleC m a
Applicative (InterpretFailSimpleC m)
-> (forall a. InterpretFailSimpleC m a)
-> (forall a.
    InterpretFailSimpleC m a
    -> InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
-> (forall a.
    InterpretFailSimpleC m a -> InterpretFailSimpleC m [a])
-> (forall a.
    InterpretFailSimpleC m a -> InterpretFailSimpleC m [a])
-> Alternative (InterpretFailSimpleC m)
InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
InterpretFailSimpleC m a -> InterpretFailSimpleC m [a]
InterpretFailSimpleC m a -> InterpretFailSimpleC m [a]
forall a. InterpretFailSimpleC m a
forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m [a]
forall a.
InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC 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 (InterpretFailSimpleC m)
forall (m :: * -> *) a. Alternative m => InterpretFailSimpleC m a
forall (m :: * -> *) a.
Alternative m =>
InterpretFailSimpleC m a -> InterpretFailSimpleC m [a]
forall (m :: * -> *) a.
Alternative m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
many :: InterpretFailSimpleC m a -> InterpretFailSimpleC m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
InterpretFailSimpleC m a -> InterpretFailSimpleC m [a]
some :: InterpretFailSimpleC m a -> InterpretFailSimpleC m [a]
$csome :: forall (m :: * -> *) a.
Alternative m =>
InterpretFailSimpleC m a -> InterpretFailSimpleC m [a]
<|> :: InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
empty :: InterpretFailSimpleC m a
$cempty :: forall (m :: * -> *) a. Alternative m => InterpretFailSimpleC m a
$cp1Alternative :: forall (m :: * -> *).
Alternative m =>
Applicative (InterpretFailSimpleC m)
Alternative, Monad (InterpretFailSimpleC m)
Alternative (InterpretFailSimpleC m)
InterpretFailSimpleC m a
Alternative (InterpretFailSimpleC m)
-> Monad (InterpretFailSimpleC m)
-> (forall a. InterpretFailSimpleC m a)
-> (forall a.
    InterpretFailSimpleC m a
    -> InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
-> MonadPlus (InterpretFailSimpleC m)
InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
forall a. InterpretFailSimpleC m a
forall a.
InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
forall (m :: * -> *). MonadPlus m => Monad (InterpretFailSimpleC m)
forall (m :: * -> *).
MonadPlus m =>
Alternative (InterpretFailSimpleC m)
forall (m :: * -> *) a. MonadPlus m => InterpretFailSimpleC m a
forall (m :: * -> *) a.
MonadPlus m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
mplus :: InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
InterpretFailSimpleC m a
-> InterpretFailSimpleC m a -> InterpretFailSimpleC m a
mzero :: InterpretFailSimpleC m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => InterpretFailSimpleC m a
$cp2MonadPlus :: forall (m :: * -> *). MonadPlus m => Monad (InterpretFailSimpleC m)
$cp1MonadPlus :: forall (m :: * -> *).
MonadPlus m =>
Alternative (InterpretFailSimpleC m)
MonadPlus
           , Monad (InterpretFailSimpleC m)
Monad (InterpretFailSimpleC m)
-> (forall a.
    (a -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a)
-> MonadFix (InterpretFailSimpleC m)
(a -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
forall a.
(a -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (InterpretFailSimpleC m)
forall (m :: * -> *) a.
MonadFix m =>
(a -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
mfix :: (a -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
$cmfix :: forall (m :: * -> *) a.
MonadFix m =>
(a -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (InterpretFailSimpleC m)
MonadFix, Monad (InterpretFailSimpleC m)
Monad (InterpretFailSimpleC m)
-> (forall a. IO a -> InterpretFailSimpleC m a)
-> MonadIO (InterpretFailSimpleC m)
IO a -> InterpretFailSimpleC m a
forall a. IO a -> InterpretFailSimpleC m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (InterpretFailSimpleC m)
forall (m :: * -> *) a.
MonadIO m =>
IO a -> InterpretFailSimpleC m a
liftIO :: IO a -> InterpretFailSimpleC m a
$cliftIO :: forall (m :: * -> *) a.
MonadIO m =>
IO a -> InterpretFailSimpleC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (InterpretFailSimpleC m)
MonadIO
           , Monad (InterpretFailSimpleC m)
e -> InterpretFailSimpleC m a
Monad (InterpretFailSimpleC m)
-> (forall e a. Exception e => e -> InterpretFailSimpleC m a)
-> MonadThrow (InterpretFailSimpleC m)
forall e a. Exception e => e -> InterpretFailSimpleC m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *).
MonadThrow m =>
Monad (InterpretFailSimpleC m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> InterpretFailSimpleC m a
throwM :: e -> InterpretFailSimpleC m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> InterpretFailSimpleC m a
$cp1MonadThrow :: forall (m :: * -> *).
MonadThrow m =>
Monad (InterpretFailSimpleC m)
MonadThrow, MonadThrow (InterpretFailSimpleC m)
MonadThrow (InterpretFailSimpleC m)
-> (forall e a.
    Exception e =>
    InterpretFailSimpleC m a
    -> (e -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a)
-> MonadCatch (InterpretFailSimpleC m)
InterpretFailSimpleC m a
-> (e -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
forall e a.
Exception e =>
InterpretFailSimpleC m a
-> (e -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *).
MonadCatch m =>
MonadThrow (InterpretFailSimpleC m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
InterpretFailSimpleC m a
-> (e -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
catch :: InterpretFailSimpleC m a
-> (e -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
InterpretFailSimpleC m a
-> (e -> InterpretFailSimpleC m a) -> InterpretFailSimpleC m a
$cp1MonadCatch :: forall (m :: * -> *).
MonadCatch m =>
MonadThrow (InterpretFailSimpleC m)
MonadCatch, MonadCatch (InterpretFailSimpleC m)
MonadCatch (InterpretFailSimpleC m)
-> (forall b.
    ((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
     -> InterpretFailSimpleC m b)
    -> InterpretFailSimpleC m b)
-> (forall b.
    ((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
     -> InterpretFailSimpleC m b)
    -> InterpretFailSimpleC m b)
-> (forall a b c.
    InterpretFailSimpleC m a
    -> (a -> ExitCase b -> InterpretFailSimpleC m c)
    -> (a -> InterpretFailSimpleC m b)
    -> InterpretFailSimpleC m (b, c))
-> MonadMask (InterpretFailSimpleC m)
InterpretFailSimpleC m a
-> (a -> ExitCase b -> InterpretFailSimpleC m c)
-> (a -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m (b, c)
((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
 -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m b
((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
 -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m b
forall b.
((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
 -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m b
forall a b c.
InterpretFailSimpleC m a
-> (a -> ExitCase b -> InterpretFailSimpleC m c)
-> (a -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
forall (m :: * -> *).
MonadMask m =>
MonadCatch (InterpretFailSimpleC m)
forall (m :: * -> *) b.
MonadMask m =>
((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
 -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m b
forall (m :: * -> *) a b c.
MonadMask m =>
InterpretFailSimpleC m a
-> (a -> ExitCase b -> InterpretFailSimpleC m c)
-> (a -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m (b, c)
generalBracket :: InterpretFailSimpleC m a
-> (a -> ExitCase b -> InterpretFailSimpleC m c)
-> (a -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m (b, c)
$cgeneralBracket :: forall (m :: * -> *) a b c.
MonadMask m =>
InterpretFailSimpleC m a
-> (a -> ExitCase b -> InterpretFailSimpleC m c)
-> (a -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m (b, c)
uninterruptibleMask :: ((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
 -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m b
$cuninterruptibleMask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
 -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m b
mask :: ((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
 -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m b
$cmask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. InterpretFailSimpleC m a -> InterpretFailSimpleC m a)
 -> InterpretFailSimpleC m b)
-> InterpretFailSimpleC m b
$cp1MonadMask :: forall (m :: * -> *).
MonadMask m =>
MonadCatch (InterpretFailSimpleC m)
MonadMask
           , MonadBase b, MonadBaseControl b
           )
  deriving m a -> InterpretFailSimpleC m a
(forall (m :: * -> *) a.
 Monad m =>
 m a -> InterpretFailSimpleC m a)
-> MonadTrans InterpretFailSimpleC
forall (m :: * -> *) a. Monad m => m a -> InterpretFailSimpleC m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> InterpretFailSimpleC m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> InterpretFailSimpleC m a
MonadTrans

deriving newtype instance
     (Monad m, Carrier (InterpretSimpleC Fail m))
  => Carrier (InterpretFailSimpleC m)

instance (Monad m, Carrier (InterpretSimpleC Fail m))
       => Fail.MonadFail (InterpretFailSimpleC m) where
  fail :: String -> InterpretFailSimpleC m a
fail = Fail (InterpretFailSimpleC m) a -> InterpretFailSimpleC m a
forall (e :: (* -> *) -> * -> *) (m :: * -> *) a.
(Member e (Derivs m), Carrier m) =>
e m a -> m a
send (Fail (InterpretFailSimpleC m) a -> InterpretFailSimpleC m a)
-> (String -> Fail (InterpretFailSimpleC m) a)
-> String
-> InterpretFailSimpleC m a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# String -> Fail (InterpretFailSimpleC m) a
forall (m :: * -> *) a. String -> Fail m a
Fail
  {-# INLINE fail #-}

-- | Transform a 'Fail' effect to a 'Throw' effect by providing a function
-- to transform a pattern match failure into an exception.
--
-- This is a less performant version of 'failToThrow' that doesn't have
-- a higher-rank type, making it much easier to use partially applied.
--
-- Unlike 'failToThrow', __you typically don't want to use this in__
-- __application code__, since this emits a 'ReaderThreads'
-- threading constraint (see 'Threaders').
failToThrowSimple :: forall e m a p
                   . ( Eff (Throw e) m
                     , Threaders '[ReaderThreads] m p
                     )
                  => (String -> e)
                  -> InterpretFailSimpleC m a
                  -> m a
failToThrowSimple :: (String -> e) -> InterpretFailSimpleC m a -> m a
failToThrowSimple String -> e
f =
    EffHandler Fail m -> InterpretSimpleC Fail m a -> m a
forall (e :: (* -> *) -> * -> *) (m :: * -> *) a
       (p :: [(* -> *) -> * -> *]).
(RepresentationalEff e, Threaders '[ReaderThreads] m p,
 Carrier m) =>
EffHandler e m -> InterpretSimpleC e m a -> m a
interpretSimple \case
      Fail s -> e -> Effly z x
forall e (m :: * -> *) a. Eff (Throw e) m => e -> m a
throw (String -> e
f String
s)
  (InterpretSimpleC Fail m a -> m a)
-> (InterpretFailSimpleC m a -> InterpretSimpleC Fail m a)
-> InterpretFailSimpleC m a
-> m a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# InterpretFailSimpleC m a -> InterpretSimpleC Fail m a
forall (m :: * -> *) a.
InterpretFailSimpleC m a -> InterpretSimpleC Fail m a
unInterpretFailSimpleC
{-# INLINE failToThrowSimple #-}