checked-exceptions
Safe HaskellNone
LanguageGHC2021

Control.Monad.CheckedExcept

Description

Basic API of CheckedExceptT

Synopsis

Types

newtype CheckedExceptT (exceptions :: [Type]) (m :: Type -> Type) a Source #

Isomorphic to ExceptT over our open-union exceptions type OneOf es.

Constructors

CheckedExceptT 

Fields

Instances

Instances details
MonadTrans (CheckedExceptT exceptions) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

lift :: Monad m => m a -> CheckedExceptT exceptions m a #

Monad m => MonadError (OneOf exceptions) (CheckedExceptT exceptions m) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

throwError :: OneOf exceptions -> CheckedExceptT exceptions m a #

catchError :: CheckedExceptT exceptions m a -> (OneOf exceptions -> CheckedExceptT exceptions m a) -> CheckedExceptT exceptions m a #

Monad m => Applicative (CheckedExceptT exceptions m) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

pure :: a -> CheckedExceptT exceptions m a #

(<*>) :: CheckedExceptT exceptions m (a -> b) -> CheckedExceptT exceptions m a -> CheckedExceptT exceptions m b #

liftA2 :: (a -> b -> c) -> CheckedExceptT exceptions m a -> CheckedExceptT exceptions m b -> CheckedExceptT exceptions m c #

(*>) :: CheckedExceptT exceptions m a -> CheckedExceptT exceptions m b -> CheckedExceptT exceptions m b #

(<*) :: CheckedExceptT exceptions m a -> CheckedExceptT exceptions m b -> CheckedExceptT exceptions m a #

Functor m => Functor (CheckedExceptT exceptions m) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

fmap :: (a -> b) -> CheckedExceptT exceptions m a -> CheckedExceptT exceptions m b #

(<$) :: a -> CheckedExceptT exceptions m b -> CheckedExceptT exceptions m a #

Monad m => Monad (CheckedExceptT exceptions m) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

(>>=) :: CheckedExceptT exceptions m a -> (a -> CheckedExceptT exceptions m b) -> CheckedExceptT exceptions m b #

(>>) :: CheckedExceptT exceptions m a -> CheckedExceptT exceptions m b -> CheckedExceptT exceptions m b #

return :: a -> CheckedExceptT exceptions m a #

MonadFail m => MonadFail (CheckedExceptT exceptions m) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

fail :: HasCallStack => String -> CheckedExceptT exceptions m a #

MonadIO m => MonadIO (CheckedExceptT exceptions m) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

liftIO :: IO a -> CheckedExceptT exceptions m a #

type CheckedExcept (es :: [Type]) a = CheckedExceptT es Identity a Source #

Pure checked exceptions.

data OneOf (es :: [Type]) Source #

A sort of pseudo-open union backed by membership witnesses.

Instances

Instances details
Monad m => MonadError (OneOf exceptions) (CheckedExceptT exceptions m) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

throwError :: OneOf exceptions -> CheckedExceptT exceptions m a #

catchError :: CheckedExceptT exceptions m a -> (OneOf exceptions -> CheckedExceptT exceptions m a) -> CheckedExceptT exceptions m a #

oneOf :: forall e (es :: [Type]). (Elem e es, CheckedException e) => e -> OneOf es Source #

Construct a checked exception value.

data ElemIx e (es :: [Type]) where Source #

Witness that e occurs at a specific position in es.

Constructors

Here :: forall e (es1 :: [Type]). ElemIx e (e ': es1) 
There :: forall e (es1 :: [Type]) f. !(ElemIx e es1) -> ElemIx e (f ': es1) 

data Subset (es1 :: [Type]) (es2 :: [Type]) where Source #

Witness that every element of es1 is contained in es2.

Constructors

SubRefl :: forall (es1 :: [Type]). Subset es1 es1 
SubNil :: forall (es2 :: [Type]). Subset ('[] :: [Type]) es2 
SubCons :: forall e (es2 :: [Type]) (es4 :: [Type]). !(ElemIx e es2) -> !(Subset es4 es2) -> Subset (e ': es4) es2 

data CaseException x (es :: [Type]) where Source #

Data type used for constructing a coverage checked case-like catch.

Constructors

CaseEndWith :: forall x. x -> CaseException x ('[] :: [Type]) 
CaseCons :: forall e x (es1 :: [Type]). Typeable e => (e -> x) -> CaseException x es1 -> CaseException x (e ': es1) 
CaseAny :: forall x (es :: [Type]). (forall e. CheckedException e => e -> x) -> CaseException x es 

pattern CaseEnd :: CaseException x ('[] :: [Type]) Source #

newtype ShowException a Source #

DerivingVia newtype wrapper to derive CheckedException from a Show instance.

Constructors

ShowException a 

Instances

Instances details
(Show a, Typeable a) => CheckedException (ShowException a) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

encodeException :: ShowException a -> String Source #

fromOneOf :: forall (es :: [Type]). OneOf es -> Maybe (ShowException a) Source #

newtype ExceptionException a Source #

DerivingVia newtype wrapper to derive CheckedException from Exception.

Constructors

ExceptionException a 

Instances

Instances details
(Typeable a, Exception a) => CheckedException (ExceptionException a) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Typeclass

class Typeable e => CheckedException e where Source #

The class for checked exceptions.

Minimal complete definition

Nothing

Methods

encodeException :: e -> String Source #

default encodeException :: Exception e => e -> String Source #

fromOneOf :: forall (es :: [Type]). OneOf es -> Maybe e Source #

Reify an exception from a OneOf when its runtime type matches e. Custom instances should preserve this contract: Just only when the payload type equals e (same rule as the default eqT witness path).

default fromOneOf :: forall (es :: [Type]). OneOf es -> Maybe e Source #

Utility functions

runCheckedExcept :: forall (es :: [Type]) a. CheckedExcept es a -> Either (OneOf es) a Source #

Get the error from CheckedExcept.

throwCheckedException :: forall e (es :: [Type]) (m :: Type -> Type) a. (Elem e es, CheckedException e, Applicative m) => e -> CheckedExceptT es m a Source #

applyAll :: forall b (es :: [Type]). (forall e. CheckedException e => e -> b) -> OneOf es -> b Source #

weakenExceptions :: forall (exceptions1 :: [Type]) (exceptions2 :: [Type]) (m :: Type -> Type) a. (Functor m, Contains exceptions1 exceptions2) => CheckedExceptT exceptions1 m a -> CheckedExceptT exceptions2 m a Source #

weakenExceptionsWith :: forall (m :: Type -> Type) (exceptions1 :: [Type]) (exceptions2 :: [Type]) a. Functor m => Subset exceptions1 exceptions2 -> CheckedExceptT exceptions1 m a -> CheckedExceptT exceptions2 m a Source #

Weaken using an explicit subset witness.

weakenOneOf :: forall (exceptions1 :: [Type]) (exceptions2 :: [Type]). Contains exceptions1 exceptions2 => OneOf exceptions1 -> OneOf exceptions2 Source #

weakenOneOfWith :: forall (exceptions1 :: [Type]) (exceptions2 :: [Type]). Subset exceptions1 exceptions2 -> OneOf exceptions1 -> OneOf exceptions2 Source #

Reconstruct a OneOf exceptions1 as part of a larger OneOf exceptions2.

withOneOf :: forall e (es :: [Type]) a. (Monoid a, CheckedException e) => OneOf es -> (e -> a) -> a Source #

Run f when the payload type equals e; otherwise return mempty.

Uses an eqT witness (like the default fromOneOf), not a custom fromOneOf instance — a custom fromOneOf returning Nothing does not affect this function.

withOneOf' :: forall (es :: [Type]) a. OneOf es -> (forall e. (Elem e es, CheckedException e, Typeable e) => e -> a) -> a Source #

caseException :: forall (es :: [Type]) x. OneOf es -> CaseException x (Nub es) -> x Source #

(<:) :: forall e x (es :: [Type]). Typeable e => (e -> x) -> CaseException x es -> CaseException x (e ': es) infixr 7 Source #

catchSomeException :: forall (m :: Type -> Type) (es :: [Type]) a. (Monad m, MonadCatch m, Elem SomeException es) => CheckedExceptT es m a -> CheckedExceptT es m a Source #

containsRefl :: forall (es :: [Type]). Subset es es Source #

Reflexive subset witness for abstract exception lists.

lookupSubset :: forall (es1 :: [Type]) (es2 :: [Type]) e. Subset es1 es2 -> ElemIx e es1 -> ElemIx e es2 Source #

Translate a membership index along a subset witness.

Type families / constraints

class Contains (es1 :: [Type]) (es2 :: [Type]) Source #

es1 is a subset of es2.

There is no reflexive instance for abstract es: use containsRefl or weakenExceptionsWith when es1 and es2 are the same type variable.

Minimal complete definition

subset

Instances

Instances details
Contains ('[] :: [Type]) es2 Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

subset :: Subset ('[] :: [Type]) es2

(Elem e es2, Contains es1 es2) => Contains (e ': es1) es2 Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

subset :: Subset (e ': es1) es2

class Elem e (es :: [Type]) Source #

Membership in a type-level list, backed by a value-level index.

Duplicate types in es are not supported: the incoherent tail instance picks the first index, so prefer Nub es (or a duplicate-free list) at the kind level.

Minimal complete definition

elemIx

Instances

Instances details
Unsatisfiable (NotElemTypeError e ('[] :: [a]) :: ErrorMessage) => Elem e ('[] :: [Type]) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

elemIx :: ElemIx e ('[] :: [Type])

Elem e (e ': es) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

elemIx :: ElemIx e (e ': es)

Elem e es => Elem e (x ': es) Source # 
Instance details

Defined in Control.Monad.CheckedExcept

Methods

elemIx :: ElemIx e (x ': es)

type family Elem' (x :: a) (xs :: [a]) :: Bool where ... Source #

Equations

Elem' (x :: a) ('[] :: [a]) = 'False 
Elem' (x :: a) (x ': xs :: [a]) = 'True 
Elem' (x :: a) (y ': xs :: [a]) = Elem' x xs 

type family NonEmpty (xs :: [a]) where ... Source #

Equations

NonEmpty ('[] :: [a]) = TypeError ('Text "type level list must be non-empty") :: Constraint 
NonEmpty (_1 :: [a]) = () 

type NotElemTypeError (x :: t) (xs :: t1) = TypeError (('ShowType x ':<>: 'Text " is not a member of ") ':<>: 'ShowType xs) :: k Source #

type family Nub (xs :: [a]) :: [a] where ... Source #

Equations

Nub ('[] :: [a]) = '[] :: [a] 
Nub (x ': xs :: [a]) = x ': Nub (Remove x xs) 

type family Remove (x :: a) (xs :: [a]) :: [a] where ... Source #

Equations

Remove (x :: a) ('[] :: [a]) = '[] :: [a] 
Remove (x :: a) (x ': ys :: [a]) = Remove x ys 
Remove (x :: a) (y ': ys :: [a]) = y ': Remove x ys 

type family (xs :: [k]) ++ (ys :: [k]) :: [k] where ... infixr 5 Source #

Equations

('[] :: [k]) ++ (ys :: [k]) = ys 
(x ': xs :: [k]) ++ (ys :: [k]) = x ': (xs ++ ys)