in-other-words-0.1.0.0: A higher-order effect system where the sky's the limit

Control.Effect.Fail

Synopsis

# Effects

newtype Fail m a where Source #

An effect corresponding to the MonadFail type class.

Effly's MonadFail instance is based on this effect; by having access to Fail, you're able to invoke handle pattern-match failure automatically inside of effect handlers.

Each Fail interpreter's associated carrier has an MonadFail instance based on how it interprets Fail. This means you can use an Fail interpreter to locally gain access to an MonadFail instance inside of application code.

Constructors

 Fail :: String -> Fail m a

# Interpretations

runFail :: forall m a p. (Threaders '[ErrorThreads] m p, Carrier m) => FailC m a -> m (Either String a) Source #

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.

failToThrow :: Eff (Throw e) m => (String -> e) -> InterpretFailReifiedC m a -> m a Source #

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).

failToNonDet :: Eff NonDet m => FailToNonDetC m a -> m a Source #

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


failToAlt :: Eff Alt m => FailToAltC m a -> m a Source #

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).

# Simple variants of interpretations

failToThrowSimple :: forall e m a p. (Eff (Throw e) m, Threaders '[ReaderThreads] m p) => (String -> e) -> InterpretFailSimpleC m a -> m a Source #

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).

class (forall e. Threads (ExceptT e) p) => ErrorThreads p Source #

ErrorThreads accepts the following primitive effects:

• Regional s
• Optional s (when s is a functor)
• BaseControl b
• Unravel p
• ListenPrim s (when s is a Monoid)
• WriterPrim s (when s is a Monoid)
• ReaderPrim i
• Mask
• Bracket
• Fix

#### Instances

Instances details
 (forall e. Threads (ExceptT e) p) => ErrorThreads p Source # Instance detailsDefined in Control.Effect.Internal.Error

# Carriers

newtype InterpretFailC h m a Source #

Like InterpretC specialized to interpret Fail, but with a MonadFail instance based on the interpreted Fail.

Constructors

 InterpretFailC FieldsunInterpretFailC :: InterpretC h Fail m a

#### Instances

Instances details