{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
module Control.Exitcode (
ExitcodeT
, Exitcode
, ExitcodeT0
, Exitcode0
, ExitcodeT1
, Exitcode1
, exitsuccess
, exitsuccess0
, exitfailure
, exitfailure0
, exitcodeValue
, exitcodeValue0
, fromExitCode
, fromExitCode'
, liftExitcode
, liftExitcodeError
, liftExitcodeError0
, hoistExitcode
, embedExitcode
, exitcode1
, runExitcodeT
, runExitcodeT0
, runExitcode
, runExitcode0
, runExitcodeT1
, runExitcode1
, exitCode
, _ExitcodeInt
, _ExitcodeInt'
, _ExitFailure
, _ExitFailureError
, _ExitSuccess
, _Exitcode1
) where
import Control.Applicative
( Applicative((<*>), pure, liftA2) )
import Control.Category ( Category((.)) )
import Control.Lens
( preview,
view,
iso,
_Left,
prism,
over,
Field1(_1),
Field2(_2),
Iso,
Lens,
Prism,
Traversal,
Traversal' )
import Control.Monad ( join, Monad(return, (>>=)) )
import Control.Monad.Cont.Class ( MonadCont(..) )
import Control.Monad.Error.Class ( MonadError(..) )
import Control.Monad.IO.Class ( MonadIO(..) )
import Control.Monad.Reader ( MonadReader(ask, local) )
import Control.Monad.RWS.Class ( MonadRWS )
import Control.Monad.State.Lazy ( MonadState(get, put) )
import Control.Monad.Trans.Maybe ( MaybeT(MaybeT) )
import Control.Monad.Writer.Class ( MonadWriter(..) )
import Data.Bifoldable ( Bifoldable(bifoldMap) )
import Data.Bifunctor ( Bifunctor(bimap) )
import Data.Bitraversable ( Bitraversable(..) )
import Data.Bool ( bool )
import Data.Either ( Either(..), either )
import Data.Eq ( Eq((==)) )
import Data.Foldable ( Foldable(foldMap) )
import Data.Function ( ($), const )
import Data.Functor ( Functor(fmap), (<$>) )
import Data.Functor.Alt ( Alt((<!>)) )
import Data.Functor.Apply ( Apply((<.>)) )
import Data.Functor.Bind ( Bind((>>-)) )
import Data.Functor.Classes
( compare1,
eq1,
showsPrec1,
showsUnaryWith,
Eq1(..),
Ord1(..),
Show1(..) )
import Data.Functor.Extend ( Extend(..) )
import Data.Functor.Identity ( Identity(Identity, runIdentity) )
import Data.Int ( Int )
import Data.Maybe ( Maybe(Nothing, Just), fromMaybe )
import Data.Monoid ( Monoid(mempty) )
import Data.Ord ( Ord(compare) )
import Data.Semigroup ( Semigroup((<>)) )
import Data.Traversable ( Traversable(traverse) )
import Data.Tuple ( uncurry )
import GHC.Show ( Show(showsPrec) )
import System.Exit ( ExitCode(..) )
newtype ExitcodeT f e a =
ExitcodeT (f (Either (e, Int) a))
type Exitcode e a =
ExitcodeT Identity e a
type ExitcodeT0 f =
ExitcodeT f () ()
type Exitcode0 =
Exitcode () ()
exitsuccess ::
Applicative f =>
a
-> ExitcodeT f e a
exitsuccess :: forall (f :: * -> *) a e. Applicative f => a -> ExitcodeT f e a
exitsuccess =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. b -> Either a b
Right
exitsuccess0 ::
Applicative f =>
ExitcodeT f e ()
exitsuccess0 :: forall (f :: * -> *) e. Applicative f => ExitcodeT f e ()
exitsuccess0 =
forall (f :: * -> *) a e. Applicative f => a -> ExitcodeT f e a
exitsuccess ()
exitfailure ::
Applicative f =>
e
-> Int
-> ExitcodeT f e ()
exitfailure :: forall (f :: * -> *) e.
Applicative f =>
e -> Int -> ExitcodeT f e ()
exitfailure e
e Int
n =
forall (f :: * -> *) e a.
Applicative f =>
e -> Int -> a -> ExitcodeT f e a
exitcodeValue e
e Int
n ()
exitfailure0 ::
Applicative f =>
Int
-> ExitcodeT0 f
exitfailure0 :: forall (f :: * -> *). Applicative f => Int -> ExitcodeT0 f
exitfailure0 =
forall (f :: * -> *) e.
Applicative f =>
e -> Int -> ExitcodeT f e ()
exitfailure ()
exitcodeValue ::
Applicative f =>
e
-> Int
-> a
-> ExitcodeT f e a
exitcodeValue :: forall (f :: * -> *) e a.
Applicative f =>
e -> Int -> a -> ExitcodeT f e a
exitcodeValue e
e Int
n =
forall (f :: * -> *) e a.
Functor f =>
f (e, Int) -> a -> ExitcodeT f e a
liftExitcodeError (forall (f :: * -> *) a. Applicative f => a -> f a
pure (e
e, Int
n))
exitcodeValue0 ::
Applicative f =>
Int
-> ExitcodeT0 f
exitcodeValue0 :: forall (f :: * -> *). Applicative f => Int -> ExitcodeT0 f
exitcodeValue0 Int
n =
forall (f :: * -> *) e a.
Applicative f =>
e -> Int -> a -> ExitcodeT f e a
exitcodeValue () Int
n ()
fromExitCode ::
Functor f =>
f ExitCode
-> ExitcodeT0 f
fromExitCode :: forall (f :: * -> *). Functor f => f ExitCode -> ExitcodeT0 f
fromExitCode f ExitCode
x =
let ExitcodeT (MaybeT f (Maybe (Either ((), Int) ()))
r) = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
Iso
(f ExitCode)
(g ExitCode)
(ExitcodeT0 (MaybeT f))
(ExitcodeT0 (MaybeT g))
exitCode f ExitCode
x
in forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall a. a -> Maybe a -> a
fromMaybe (forall a b. b -> Either a b
Right ()) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Maybe (Either ((), Int) ()))
r)
fromExitCode' ::
ExitCode
-> Exitcode0
fromExitCode' :: ExitCode -> Exitcode0
fromExitCode' =
forall (f :: * -> *). Functor f => f ExitCode -> ExitcodeT0 f
fromExitCode forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. a -> Identity a
Identity
exitCode ::
(Functor f, Functor g) =>
Iso
(f ExitCode)
(g ExitCode)
(ExitcodeT0 (MaybeT f))
(ExitcodeT0 (MaybeT g))
exitCode :: forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
Iso
(f ExitCode)
(g ExitCode)
(ExitcodeT0 (MaybeT f))
(ExitcodeT0 (MaybeT g))
exitCode =
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
(\f ExitCode
x -> forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT ((\case
ExitCode
ExitSuccess ->
forall a. a -> Maybe a
Just (forall a b. b -> Either a b
Right ())
ExitFailure Int
0 ->
forall a. Maybe a
Nothing
ExitFailure Int
n ->
forall a. a -> Maybe a
Just (forall a b. a -> Either a b
Left ((), Int
n))) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f ExitCode
x)))
(\(ExitcodeT (MaybeT g (Maybe (Either ((), Int) ()))
x)) -> (\case
Just (Right ()) ->
ExitCode
ExitSuccess
Maybe (Either ((), Int) ())
Nothing ->
Int -> ExitCode
ExitFailure Int
0
Just (Left ((), Int
n)) ->
Int -> ExitCode
ExitFailure Int
n) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g (Maybe (Either ((), Int) ()))
x)
runExitcodeT ::
ExitcodeT f e a
-> f (Either (e, Int) a)
runExitcodeT :: forall (f :: * -> *) e a. ExitcodeT f e a -> f (Either (e, Int) a)
runExitcodeT (ExitcodeT f (Either (e, Int) a)
x) =
f (Either (e, Int) a)
x
runExitcodeT0 ::
Functor f =>
ExitcodeT0 f
-> f (Maybe Int)
runExitcodeT0 :: forall (f :: * -> *). Functor f => ExitcodeT0 f -> f (Maybe Int)
runExitcodeT0 ExitcodeT0 f
x =
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview (forall a c b. Prism (Either a c) (Either b c) a b
_Left forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall s t a b. Field2 s t a b => Lens s t a b
_2) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) e a. ExitcodeT f e a -> f (Either (e, Int) a)
runExitcodeT ExitcodeT0 f
x
runExitcode ::
Exitcode e a
-> Either (e, Int) a
runExitcode :: forall e a. Exitcode e a -> Either (e, Int) a
runExitcode =
forall a. Identity a -> a
runIdentity forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) e a. ExitcodeT f e a -> f (Either (e, Int) a)
runExitcodeT
runExitcode0 ::
Exitcode0
-> Maybe Int
runExitcode0 :: Exitcode0 -> Maybe Int
runExitcode0 =
forall a. Identity a -> a
runIdentity forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *). Functor f => ExitcodeT0 f -> f (Maybe Int)
runExitcodeT0
_ExitcodeInt ::
(Functor f, Functor f') =>
Iso
(ExitcodeT0 f)
(ExitcodeT0 f')
(f Int)
(f' Int)
_ExitcodeInt :: forall (f :: * -> *) (f' :: * -> *).
(Functor f, Functor f') =>
Iso (ExitcodeT0 f) (ExitcodeT0 f') (f Int) (f' Int)
_ExitcodeInt =
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
(\(ExitcodeT f (Either ((), Int) ())
x) -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t a b. Field2 s t a b => Lens s t a b
_2) (\() -> Int
0)) f (Either ((), Int) ())
x)
(\f' Int
x -> forall (f :: * -> *) e a.
Functor f =>
f (e, Int) -> a -> ExitcodeT f e a
liftExitcodeError (((),) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f' Int
x) ())
_ExitcodeInt' ::
Traversable f =>
Traversal'
(ExitcodeT0 f)
Int
_ExitcodeInt' :: forall (f :: * -> *).
Traversable f =>
Traversal' (ExitcodeT0 f) Int
_ExitcodeInt' =
forall (f :: * -> *) (f' :: * -> *).
(Functor f, Functor f') =>
Iso (ExitcodeT0 f) (ExitcodeT0 f') (f Int) (f' Int)
_ExitcodeInt forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
_ExitFailure ::
Traversable f =>
Traversal
(ExitcodeT f e ())
(ExitcodeT f e' ())
(e, Int)
(e', Int)
_ExitFailure :: forall (f :: * -> *) e e'.
Traversable f =>
Traversal (ExitcodeT f e ()) (ExitcodeT f e' ()) (e, Int) (e', Int)
_ExitFailure (e, Int) -> f (e', Int)
f (ExitcodeT f (Either (e, Int) ())
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\(e, Int)
z -> forall (f :: * -> *) e a. ExitcodeT f e a -> f (Either (e, Int) a)
runExitcodeT (forall (f :: * -> *) e a.
Functor f =>
f (e, Int) -> a -> ExitcodeT f e a
liftExitcodeError ((e, Int) -> f (e', Int)
f (e, Int)
z) ())) (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure)) f (Either (e, Int) ())
x
_ExitFailureError ::
Traversable f =>
Traversal
(ExitcodeT f e a)
(ExitcodeT f e' a)
e
e'
_ExitFailureError :: forall (f :: * -> *) e a e'.
Traversable f =>
Traversal (ExitcodeT f e a) (ExitcodeT f e' a) e e'
_ExitFailureError e -> f e'
f (ExitcodeT f (Either (e, Int) a)
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\(e
e, Int
n) -> (\e'
e' -> forall a b. a -> Either a b
Left (e'
e', Int
n)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> f e'
f e
e) (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. b -> Either a b
Right)) f (Either (e, Int) a)
x
_ExitSuccess ::
Prism
(Exitcode e a)
(Exitcode e a')
a
a'
_ExitSuccess :: forall e a a'. Prism (Exitcode e a) (Exitcode e a') a a'
_ExitSuccess =
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism
forall (f :: * -> *) a e. Applicative f => a -> ExitcodeT f e a
exitsuccess
(\(ExitcodeT (Identity Either (e, Int) a
x)) ->
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over forall a c b. Prism (Either a c) (Either b c) a b
_Left (forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. a -> Identity a
Identity forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) Either (e, Int) a
x
)
instance Functor f => Functor (ExitcodeT f e) where
fmap :: forall a b. (a -> b) -> ExitcodeT f e a -> ExitcodeT f e b
fmap a -> b
f (ExitcodeT f (Either (e, Int) a)
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) f (Either (e, Int) a)
x)
instance Monad f => Apply (ExitcodeT f e) where
ExitcodeT f (Either (e, Int) (a -> b))
f <.> :: forall a b.
ExitcodeT f e (a -> b) -> ExitcodeT f e a -> ExitcodeT f e b
<.> ExitcodeT f (Either (e, Int) a)
a =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (f (Either (e, Int) (a -> b))
f forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) (\a -> b
f' -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f') f (Either (e, Int) a)
a))
instance Monad f => Applicative (ExitcodeT f e) where
pure :: forall a. a -> ExitcodeT f e a
pure =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
ExitcodeT f (Either (e, Int) (a -> b))
f <*> :: forall a b.
ExitcodeT f e (a -> b) -> ExitcodeT f e a -> ExitcodeT f e b
<*> ExitcodeT f (Either (e, Int) a)
a =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (f (Either (e, Int) (a -> b))
f forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) (\a -> b
f' -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f') f (Either (e, Int) a)
a))
instance Monad f => Bind (ExitcodeT f e) where
>>- :: forall a b.
ExitcodeT f e a -> (a -> ExitcodeT f e b) -> ExitcodeT f e b
(>>-) =
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(>>=)
instance Monad f => Monad (ExitcodeT f e) where
return :: forall a. a -> ExitcodeT f e a
return =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (m :: * -> *) a. Monad m => a -> m a
return forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (m :: * -> *) a. Monad m => a -> m a
return
ExitcodeT f (Either (e, Int) a)
x >>= :: forall a b.
ExitcodeT f e a -> (a -> ExitcodeT f e b) -> ExitcodeT f e b
>>= a -> ExitcodeT f e b
f =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT
(f (Either (e, Int) a)
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) (forall (f :: * -> *) e a. ExitcodeT f e a -> f (Either (e, Int) a)
runExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> ExitcodeT f e b
f))
instance Monad f => Alt (ExitcodeT f e) where
ExitcodeT f (Either (e, Int) a)
a <!> :: forall a. ExitcodeT f e a -> ExitcodeT f e a -> ExitcodeT f e a
<!> ExitcodeT f (Either (e, Int) a)
b =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (f (Either (e, Int) a)
a forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const f (Either (e, Int) a)
b) (forall (f :: * -> *) a. Applicative f => a -> f a
pure f (Either (e, Int) a)
a))
instance (Semigroup a, Applicative f) => Semigroup (ExitcodeT f e a) where
ExitcodeT f (Either (e, Int) a)
a <> :: ExitcodeT f e a -> ExitcodeT f e a -> ExitcodeT f e a
<> ExitcodeT f (Either (e, Int) a)
b =
let jn :: Either a b -> Either a b -> Either a b
jn (Left a
_) Either a b
x = Either a b
x
jn Either a b
x (Left a
_) = Either a b
x
jn (Right b
a1) (Right b
a2) = forall a b. b -> Either a b
Right (b
a1 forall a. Semigroup a => a -> a -> a
<> b
a2)
in forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall {b} {a}.
Semigroup b =>
Either a b -> Either a b -> Either a b
jn f (Either (e, Int) a)
a f (Either (e, Int) a)
b)
instance (Monoid a, Applicative f) => Monoid (ExitcodeT f e a) where
mempty :: ExitcodeT f e a
mempty =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a b. b -> Either a b
Right forall a. Monoid a => a
mempty))
instance Extend f => Extend (ExitcodeT f e) where
duplicated :: forall a. ExitcodeT f e a -> ExitcodeT f e (ExitcodeT f e a)
duplicated (ExitcodeT f (Either (e, Int) a)
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall (w :: * -> *) a b. Extend w => (w a -> b) -> w a -> w b
extended (forall a b. b -> Either a b
Right forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT) f (Either (e, Int) a)
x)
instance (Eq1 f, Eq e, Eq a) => Eq (ExitcodeT f e a) where
ExitcodeT f (Either (e, Int) a)
a == :: ExitcodeT f e a -> ExitcodeT f e a -> Bool
== ExitcodeT f (Either (e, Int) a)
b =
f (Either (e, Int) a)
a forall (f :: * -> *) a. (Eq1 f, Eq a) => f a -> f a -> Bool
`eq1` f (Either (e, Int) a)
b
instance (Eq1 f, Eq e) => Eq1 (ExitcodeT f e) where
liftEq :: forall a b.
(a -> b -> Bool) -> ExitcodeT f e a -> ExitcodeT f e b -> Bool
liftEq a -> b -> Bool
f (ExitcodeT f (Either (e, Int) a)
a) (ExitcodeT f (Either (e, Int) b)
b) =
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq (forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
f) f (Either (e, Int) a)
a f (Either (e, Int) b)
b
instance (Ord1 f, Ord e, Ord a) => Ord (ExitcodeT f e a) where
ExitcodeT f (Either (e, Int) a)
a compare :: ExitcodeT f e a -> ExitcodeT f e a -> Ordering
`compare` ExitcodeT f (Either (e, Int) a)
b =
f (Either (e, Int) a)
a forall (f :: * -> *) a. (Ord1 f, Ord a) => f a -> f a -> Ordering
`compare1` f (Either (e, Int) a)
b
instance (Ord1 f, Ord e) => Ord1 (ExitcodeT f e) where
liftCompare :: forall a b.
(a -> b -> Ordering)
-> ExitcodeT f e a -> ExitcodeT f e b -> Ordering
liftCompare a -> b -> Ordering
f (ExitcodeT f (Either (e, Int) a)
a) (ExitcodeT f (Either (e, Int) b)
b) =
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare (forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
f) f (Either (e, Int) a)
a f (Either (e, Int) b)
b
instance (Show1 f, Show e, Show a) => Show (ExitcodeT f e a) where
showsPrec :: Int -> ExitcodeT f e a -> ShowS
showsPrec Int
d (ExitcodeT f (Either (e, Int) a)
m) =
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith forall (f :: * -> *) a. (Show1 f, Show a) => Int -> f a -> ShowS
showsPrec1 String
"ExitcodeT" Int
d f (Either (e, Int) a)
m
instance (Show1 f, Show e) => Show1 (ExitcodeT f e) where
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> ExitcodeT f e a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl Int
d (ExitcodeT f (Either (e, Int) a)
fa) =
let showsPrecF :: Int -> f (Either (e, Int) a) -> ShowS
showsPrecF = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec) (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS
liftShowList) (Int -> a -> ShowS
sp, [a] -> ShowS
sl)
in forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith Int -> f (Either (e, Int) a) -> ShowS
showsPrecF String
"ExitcodeT" Int
d f (Either (e, Int) a)
fa
instance Foldable f => Foldable (ExitcodeT f e) where
foldMap :: forall m a. Monoid m => (a -> m) -> ExitcodeT f e a -> m
foldMap a -> m
f (ExitcodeT f (Either (e, Int) a)
x) =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f) f (Either (e, Int) a)
x
instance Traversable f => Traversable (ExitcodeT f e) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ExitcodeT f e a -> f (ExitcodeT f e b)
traverse a -> f b
f (ExitcodeT f (Either (e, Int) a)
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f) f (Either (e, Int) a)
x
instance MonadIO f => MonadIO (ExitcodeT f e) where
liftIO :: forall a. IO a -> ExitcodeT f e a
liftIO IO a
io =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO a
io)
liftExitcode ::
Functor f =>
f a
-> ExitcodeT f e a
liftExitcode :: forall (f :: * -> *) a e. Functor f => f a -> ExitcodeT f e a
liftExitcode f a
x =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
x)
liftExitcodeError ::
Functor f =>
f (e, Int)
-> a
-> ExitcodeT f e a
liftExitcodeError :: forall (f :: * -> *) e a.
Functor f =>
f (e, Int) -> a -> ExitcodeT f e a
liftExitcodeError f (e, Int)
x a
a =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT ((\(e
e, Int
n) -> forall a. a -> a -> Bool -> a
bool (forall a b. a -> Either a b
Left (e
e, Int
n)) (forall a b. b -> Either a b
Right a
a) (Int
n forall a. Eq a => a -> a -> Bool
== Int
0)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (e, Int)
x)
liftExitcodeError0 ::
Functor f =>
f Int
-> ExitcodeT f () ()
liftExitcodeError0 :: forall (f :: * -> *). Functor f => f Int -> ExitcodeT f () ()
liftExitcodeError0 f Int
x =
forall (f :: * -> *) e a.
Functor f =>
f (e, Int) -> a -> ExitcodeT f e a
liftExitcodeError (((),) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f Int
x) ()
hoistExitcode ::
(forall x. f x -> g x)
-> ExitcodeT f e a
-> ExitcodeT g e a
hoistExitcode :: forall (f :: * -> *) (g :: * -> *) e a.
(forall x. f x -> g x) -> ExitcodeT f e a -> ExitcodeT g e a
hoistExitcode forall x. f x -> g x
nat (ExitcodeT f (Either (e, Int) a)
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall x. f x -> g x
nat f (Either (e, Int) a)
x)
embedExitcode ::
Functor g =>
(forall x. f x -> ExitcodeT g e x)
-> ExitcodeT f e a
-> ExitcodeT g e a
embedExitcode :: forall (g :: * -> *) (f :: * -> *) e a.
Functor g =>
(forall x. f x -> ExitcodeT g e x)
-> ExitcodeT f e a -> ExitcodeT g e a
embedExitcode forall x. f x -> ExitcodeT g e x
nat (ExitcodeT f (Either (e, Int) a)
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) e a. ExitcodeT f e a -> f (Either (e, Int) a)
runExitcodeT (forall x. f x -> ExitcodeT g e x
nat f (Either (e, Int) a)
x))
instance MonadReader r f => MonadReader r (ExitcodeT f e) where
ask :: ExitcodeT f e r
ask =
forall (f :: * -> *) a e. Functor f => f a -> ExitcodeT f e a
liftExitcode forall r (m :: * -> *). MonadReader r m => m r
ask
local :: forall a. (r -> r) -> ExitcodeT f e a -> ExitcodeT f e a
local r -> r
f (ExitcodeT f (Either (e, Int) a)
m) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local r -> r
f f (Either (e, Int) a)
m)
instance MonadWriter w f => MonadWriter w (ExitcodeT f e) where
writer :: forall a. (a, w) -> ExitcodeT f e a
writer (a, w)
t =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall w (m :: * -> *) a. MonadWriter w m => (a, w) -> m a
writer (a, w)
t
listen :: forall a. ExitcodeT f e a -> ExitcodeT f e (a, w)
listen (ExitcodeT f (Either (e, Int) a)
m) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT ((\(Either (e, Int) a
e, w
w) -> (,w
w) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Either (e, Int) a
e) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen f (Either (e, Int) a)
m)
tell :: w -> ExitcodeT f e ()
tell =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. b -> Either a b
Right forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell
pass :: forall a. ExitcodeT f e (a, w -> w) -> ExitcodeT f e a
pass ExitcodeT f e (a, w -> w)
e =
do ((a
a, w -> w
f), w
w) <- forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen ExitcodeT f e (a, w -> w)
e
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell (w -> w
f w
w)
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
instance MonadState s f => MonadState s (ExitcodeT f e) where
get :: ExitcodeT f e s
get =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. b -> Either a b
Right forall s (m :: * -> *). MonadState s m => m s
get)
put :: s -> ExitcodeT f e ()
put =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. b -> Either a b
Right forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall s (m :: * -> *). MonadState s m => s -> m ()
put
instance MonadError e f => MonadError e (ExitcodeT f e') where
throwError :: forall a. e -> ExitcodeT f e' a
throwError =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. b -> Either a b
Right forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
catchError :: forall a.
ExitcodeT f e' a -> (e -> ExitcodeT f e' a) -> ExitcodeT f e' a
catchError (ExitcodeT f (Either (e', Int) a)
f) e -> ExitcodeT f e' a
h =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
catchError f (Either (e', Int) a)
f (forall (f :: * -> *) e a. ExitcodeT f e a -> f (Either (e, Int) a)
runExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. e -> ExitcodeT f e' a
h))
instance MonadRWS r w s f => MonadRWS r w s (ExitcodeT f e)
instance MonadCont f => MonadCont (ExitcodeT f e) where
callCC :: forall a b.
((a -> ExitcodeT f e b) -> ExitcodeT f e a) -> ExitcodeT f e a
callCC =
let liftCallCC :: (((Either a a -> f (Either (e, Int) a)) -> f (Either (e, Int) a))
-> f (Either (e, Int) a))
-> ((a -> ExitcodeT f e a) -> ExitcodeT f e a) -> ExitcodeT f e a
liftCallCC ((Either a a -> f (Either (e, Int) a)) -> f (Either (e, Int) a))
-> f (Either (e, Int) a)
callCC' (a -> ExitcodeT f e a) -> ExitcodeT f e a
f =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ((Either a a -> f (Either (e, Int) a)) -> f (Either (e, Int) a))
-> f (Either (e, Int) a)
callCC' forall a b. (a -> b) -> a -> b
$
\Either a a -> f (Either (e, Int) a)
c -> forall (f :: * -> *) e a. ExitcodeT f e a -> f (Either (e, Int) a)
runExitcodeT ((a -> ExitcodeT f e a) -> ExitcodeT f e a
f (forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either a a -> f (Either (e, Int) a)
c forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. b -> Either a b
Right))
in forall {a} {a} {f :: * -> *} {e} {a} {f :: * -> *} {e} {a}
{f :: * -> *} {e} {a}.
(((Either a a -> f (Either (e, Int) a)) -> f (Either (e, Int) a))
-> f (Either (e, Int) a))
-> ((a -> ExitcodeT f e a) -> ExitcodeT f e a) -> ExitcodeT f e a
liftCallCC forall (m :: * -> *) a b. MonadCont m => ((a -> m b) -> m a) -> m a
callCC
instance Functor f => Bifunctor (ExitcodeT f) where
bimap :: forall a b c d.
(a -> b) -> (c -> d) -> ExitcodeT f a c -> ExitcodeT f b d
bimap a -> b
f c -> d
g (ExitcodeT f (Either (a, Int) c)
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over forall s t a b. Field1 s t a b => Lens s t a b
_1 a -> b
f) c -> d
g) f (Either (a, Int) c)
x)
instance Foldable f => Bifoldable (ExitcodeT f) where
bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> ExitcodeT f a b -> m
bifoldMap a -> m
f b -> m
g (ExitcodeT f (Either (a, Int) b)
x) =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (a -> m
f forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t a b. Field1 s t a b => Lens s t a b
_1) b -> m
g) f (Either (a, Int) b)
x
instance Traversable f => Bitraversable (ExitcodeT f) where
bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> ExitcodeT f a b -> f (ExitcodeT f c d)
bitraverse a -> f c
f b -> f d
g (ExitcodeT f (Either (a, Int) b)
x) =
forall (f :: * -> *) e a. f (Either (e, Int) a) -> ExitcodeT f e a
ExitcodeT forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse (\(a
a, Int
n) -> (, Int
n) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f c
f a
a) b -> f d
g) f (Either (a, Int) b)
x
type ExitcodeT1 f a =
ExitcodeT f a a
type Exitcode1 a =
ExitcodeT1 Identity a
exitcode1 ::
Applicative f =>
Int
-> a
-> ExitcodeT1 f a
exitcode1 :: forall (f :: * -> *) a. Applicative f => Int -> a -> ExitcodeT1 f a
exitcode1 Int
n a
a =
forall (f :: * -> *) e a.
Applicative f =>
e -> Int -> a -> ExitcodeT f e a
exitcodeValue a
a Int
n a
a
runExitcodeT1 ::
ExitcodeT1 f a
-> f (Either (a, Int) a)
runExitcodeT1 :: forall (f :: * -> *) a. ExitcodeT1 f a -> f (Either (a, Int) a)
runExitcodeT1 (ExitcodeT f (Either (a, Int) a)
x) =
f (Either (a, Int) a)
x
runExitcode1 ::
Exitcode1 a
-> Either (a, Int) a
runExitcode1 :: forall a. Exitcode1 a -> Either (a, Int) a
runExitcode1 =
forall a. Identity a -> a
runIdentity forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. ExitcodeT1 f a -> f (Either (a, Int) a)
runExitcodeT1
_Exitcode1 ::
Lens
(Exitcode1 a)
(Exitcode1 a')
a
a'
_Exitcode1 :: forall a a'. Lens (Exitcode1 a) (Exitcode1 a') a a'
_Exitcode1 a -> f a'
f =
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
(\(a
a, Int
n) -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a. Applicative f => Int -> a -> ExitcodeT1 f a
exitcode1 Int
n) (a -> f a'
f a
a))
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a. Applicative f => Int -> a -> ExitcodeT1 f a
exitcode1 Int
0) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> f a'
f)
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Exitcode1 a -> Either (a, Int) a
runExitcode1