polysemy-1.5.0.0: Higher-order, low-boilerplate free monads.
Safe HaskellNone
LanguageHaskell2010

Polysemy.Error

Synopsis

Effect

data Error e m a where Source #

Constructors

Throw :: e -> Error e m a 
Catch :: forall e m a. m a -> (e -> m a) -> Error e m a 

Instances

Instances details
type DefiningModule (Error :: Type -> (k -> Type) -> k -> Type) Source # 
Instance details

Defined in Polysemy.Error

type DefiningModule (Error :: Type -> (k -> Type) -> k -> Type) = "Polysemy.Error"

Actions

throw :: forall e r a. MemberWithError (Error e) r => e -> Sem r a Source #

catch :: forall e r a. MemberWithError (Error e) r => Sem r a -> (e -> Sem r a) -> Sem r a Source #

fromEither :: Member (Error e) r => Either e a -> Sem r a Source #

Upgrade an Either into an Error effect.

Since: 0.5.1.0

fromEitherM :: forall e m r a. (Member (Error e) r, Member (Embed m) r) => m (Either e a) -> Sem r a Source #

A combinator doing embed and fromEither at the same time. Useful for interoperating with IO.

Since: 0.5.1.0

fromException :: forall e r a. (Exception e, Member (Error e) r, Member (Embed IO) r) => IO a -> Sem r a Source #

Lift an exception generated from an IO action into an Error.

fromExceptionVia :: (Exception exc, Member (Error err) r, Member (Embed IO) r) => (exc -> err) -> IO a -> Sem r a Source #

Like fromException, but with the ability to transform the exception before turning it into an Error.

fromExceptionSem :: forall e r a. (Exception e, Member (Error e) r, Member (Final IO) r) => Sem r a -> Sem r a Source #

Run a Sem r action, converting any IO exception generated by it into an Error.

fromExceptionSemVia :: (Exception exc, Member (Error err) r, Member (Final IO) r) => (exc -> err) -> Sem r a -> Sem r a Source #

Like fromExceptionSem, but with the ability to transform the exception before turning it into an Error.

note :: Member (Error e) r => e -> Maybe a -> Sem r a Source #

Attempt to extract a Just a from a Maybe a, throwing the provided exception upon Nothing.

try :: Member (Error e) r => Sem r a -> Sem r (Either e a) Source #

Similar to catch, but returns an Either result which is (Right a) if no exception of type e was thrown, or (Left ex) if an exception of type e was thrown and its value is ex.

tryJust :: Member (Error e) r => (e -> Maybe b) -> Sem r a -> Sem r (Either b a) Source #

A variant of try that takes an exception predicate to select which exceptions are caught (c.f. catchJust). If the exception does not match the predicate, it is re-thrown.

catchJust Source #

Arguments

:: Member (Error e) r 
=> (e -> Maybe b)

Predicate to select exceptions

-> Sem r a

Computation to run

-> (b -> Sem r a)

Handler

-> Sem r a 

The function catchJust is like catch, but it takes an extra argument which is an exception predicate, a function which selects which type of exceptions we're interested in.

Interpretations

runError :: Sem (Error e ': r) a -> Sem r (Either e a) Source #

Run an Error effect in the style of ExceptT.

mapError :: forall e1 e2 r a. Member (Error e2) r => (e1 -> e2) -> Sem (Error e1 ': r) a -> Sem r a Source #

Transform one Error into another. This function can be used to aggregate multiple errors into a single type.

Since: 1.0.0.0

errorToIOFinal :: (Typeable e, Member (Final IO) r) => Sem (Error e ': r) a -> Sem r (Either e a) Source #

Run an Error effect as an IO Exception through final IO. This interpretation is significantly faster than runError.

Beware: Effects that aren't interpreted in terms of IO will have local state semantics in regards to Error effects interpreted this way. See Final.

Since: 1.2.0.0

lowerError Source #

Arguments

:: (Typeable e, Member (Embed IO) r) 
=> (forall x. Sem r x -> IO x)

Strategy for lowering a Sem action down to IO. This is likely some combination of runM and other interpreters composed via .@.

-> Sem (Error e ': r) a 
-> Sem r (Either e a) 

Deprecated: Use errorToIOFinal instead

Run an Error effect as an IO Exception. This interpretation is significantly faster than runError, at the cost of being less flexible.

Since: 1.0.0.0