data-effects-0.3.0.1: A basic framework for effect systems based on effects represented by GADTs.
Copyright(c) 2023 Sayo Koyoneda
LicenseMPL-2.0 (see the file LICENSE)
Maintainer[email protected]
Safe HaskellNone
LanguageGHC2021

Data.Effect.Except

Description

An effect to escape from the normal control structure with an exception value in the middle of a context.

Synopsis

Documentation

data Throw e a where Source #

An effect to escape from the normal control structure with an exception value of type e in the middle of a context.

Constructors

Throw :: forall e a. e -> Throw e a

Throws an exception; that is, escapes from the normal control structure with an exception value in the middle of a context.

data Catch e (f :: Type -> Type) a where Source #

An effect to catch exceptions.

Constructors

Catch

Catches exceptions within a scope and processes them according to the given exception handler.

Fields

  • :: forall (f :: Type -> Type) a e. f a

    The scope in which to catch exceptions.

  • -> (e -> f a)

    Exception handler. Defines the processing to perform when an exception is thrown within the scope.

  • -> Catch e f a
     

Instances

Instances details
() => HFunctor (Catch e) Source # 
Instance details

Defined in Data.Effect.Except

Methods

hfmap :: forall (f :: Type -> Type) (g :: Type -> Type). (f :-> g) -> Catch e f :-> Catch e g #

type LThrow e = LiftFOE (Throw e) Source #

pattern LThrow :: forall a e f a1. () => forall. (a ~ a1, ()) => e -> LiftFOE (Throw e) f a Source #

throw :: forall e a f. SendFOE (Throw e) f => e -> f a Source #

Throws an exception; that is, escapes from the normal control structure with an exception value in the middle of a context.

throw' :: forall {k} (tag :: k) e a f. SendFOE (Tag (Throw e) tag) f => e -> f a Source #

Throws an exception; that is, escapes from the normal control structure with an exception value in the middle of a context.

throw'' :: forall {k} (key :: k) e a f. SendFOEBy key (Throw e) f => e -> f a Source #

Throws an exception; that is, escapes from the normal control structure with an exception value in the middle of a context.

catch Source #

Arguments

:: forall a e f. SendHOE (Catch e) f 
=> f a 
-> (e -> f a)

Exception handler. Defines the processing to perform when an exception is thrown within the scope.

-> f a 

Catches exceptions within a scope and processes them according to the given exception handler.

catch' Source #

Arguments

:: forall {k} (tag :: k) a e f. SendHOE (TagH (Catch e) tag) f 
=> f a 
-> (e -> f a)

Exception handler. Defines the processing to perform when an exception is thrown within the scope.

-> f a 

Catches exceptions within a scope and processes them according to the given exception handler.

catch'' Source #

Arguments

:: forall {k} (key :: k) a e f. SendHOEBy key (Catch e) f 
=> f a 
-> (e -> f a)

Exception handler. Defines the processing to perform when an exception is thrown within the scope.

-> f a 

Catches exceptions within a scope and processes them according to the given exception handler.

liftEither :: (Throw e <: f, Applicative f) => Either e a -> f a Source #

Throws the given Either value as an exception if it is Left.

joinEither :: (Throw e <: m, Monad m) => m (Either e a) -> m a Source #

Throws the result of the given action as an exception if it is Left.

joinExcept :: Monad m => Either (m a) a -> m a Source #

If the given Either value is Left, execute it as an action.

exc :: Monad m => m (Either (m a) a) -> m a Source #

If the result of the given action is Left, execute it as an action.

withExcept Source #

Arguments

:: (Catch e <<: f, Throw e <: f, Applicative f) 
=> f a

Scope to which the exception handler applies

-> (e -> f ())

Exception handler

-> f a 

If an exception occurs, executes the given exception handler, but the exception is not stopped there and is rethrown.

onExcept Source #

Arguments

:: (Catch e <<: f, Throw e <: f, Applicative f) 
=> f a

Scope in which to detect exceptions

-> f ()

Action to execute in case of an exception

-> f a 

If an exception occurs, executes the specified action, but the exception is not stopped there and is rethrown.