ModuleFailT-0.1.2.0Haskell2010
Control.Monad.Trans.Fail
- 3 types
- 20 values
- PackageFailT-0.1.2.0
- Exports23
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceFail.hs
Fail
6 declarationsUnwrap the pure Fail monad and reveal the underlying result of monadic computation.
runFail (fail "Something went wrong") :: Either String ()Left "Something went wrong"runFail (failT "Something went wrong" >> pure ())Left "Something went wrong"import Control.ApplicativerunFail (failT "Something could have gone wrong" <|> pure ())Right ()
All errors accrued during the monadic computation will be combined using the Semigroup instance and delimited by a comma:
runFail (fail "One thing went wrong" <|> fail "Another thing went wrong") :: Either String ()Left "One thing went wrong, Another thing went wrong"
Failing with one of instances functions mempty or empty will yield a no-reason error report:
runFail mempty :: Either String ()Left "No failure reason given"
This is a variant of runFailAgg where only the error reported for the very last failed computation will be produced and others discarded. This is useful when it is not relevant to retain information about all the attempts and only the last one matters, eg. parsing with backtracking.
Convert a Fail monad computation in an Either, where the Left will contain all failures in the same order they where received, or Right upon a successful computation.
runFailAgg (fail "One bad thing" <|> fail "Another bad thing") :: Either [String] ()Left ["One bad thing","Another bad thing"]runFailAgg (fail "A bad thing" <|> pure "A good thing") :: Either [String] StringRight "A good thing"
Throw an error if there was a failure, otherwise return the result of computation. Use throwFailT in case you'd like to handle an actual exception in some other underlying monad.
errorFail (fail "This didn't work" :: Fail String ())*** Exception: "This didn't work"CallStack (from HasCallStack):...errorFail (fail "This didn't work" <|> pure "That Worked" :: Fail String String)"That Worked"
Same as errorFail, but without the stack trace:
errorFailWithoutStackTrace (fail "This didn't work" :: Fail String ())*** Exception: "This didn't work"errorFailWithoutStackTrace (fail "This didn't work" <|> pure "That Worked" :: Fail String String)"That Worked"
FailT
14 declarationsFail monad transformer that plays well with MonadFail type class.
Instances31MonadRWS, MonadAccum, MonadError, MonadReader, MonadState, MonadWriter, …
MonadRWS r w s m => MonadRWS r w s (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadAccum w m => MonadAccum w (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadError e m => MonadError e (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadReader r m => MonadReader r (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadState s m => MonadState s (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadWriter w m => MonadWriter w (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadSelect r m => MonadSelect r (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadTrans (FailT e)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonad m => Monad (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailShort-circuites on the first failing operation.
Functor m => Functor (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadFix m => MonadFix (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(IsString e, Monad m) => MonadFail (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonad m => Applicative (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailFoldable f => Foldable (FailT e f)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailTraversable f => Traversable (FailT e f)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonad m => Alternative (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailShort-circuits on the first successful operation, combines failures otherwise.
MonadIO m => MonadIO (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadZip m => MonadZip (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Eq e, Eq1 m) => Eq1 (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Ord e, Ord1 m) => Ord1 (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Read e, Read1 m) => Read1 (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Show e, Show1 m) => Show1 (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailContravariant f => Contravariant (FailT e f)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadCont m => MonadCont (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailMonadThrow m => MonadThrow (FailT e m)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Eq e, Eq1 m, Eq a) => Eq (FailT e m a)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Ord e, Ord1 m, Ord a) => Ord (FailT e m a)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Read e, Read1 m, Read a) => Read (FailT e m a)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Show e, Show1 m, Show a) => Show (FailT e m a)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail(Monad m, Semigroup a) => Semigroup (FailT e m a)Defined in FailT-0.1.2.0 · Control.Monad.Trans.FailExecutes all monadic actions and combines all successful results using a Semigroup instance. Combines together all failures as well, until a successful operation.
(Monad m, Semigroup a) => Monoid (FailT e m a)Defined in FailT-0.1.2.0 · Control.Monad.Trans.Fail
An exception that is produced by the FailT monad transformer.
Constructors
FailException :: (Typeable e, Show e) => [e] -> CallStack -> FailExceptionfailMessages :: [e]failCallStack :: CallStack
Instances2Show, Exception
Show FailExceptionDefined in FailT-0.1.2.0 · Control.Monad.Trans.FailException FailExceptionDefined in FailT-0.1.2.0 · Control.Monad.Trans.Fail
Similar to failT, but accepts a list of failures.
runFailAgg (foldMap failT (xs :: [String])) == runFailAgg (failManyT xs)Similar to runFail, except underlying monad is not restricted to Identity.
Unwrap the FailT monad transformer and produce an action that can be executed in the underlying monad and, which will produce either a comma delimited error message upon a failure or the result otherwise.
runFailT (failT "Could have failed" <|> liftIO (putStrLn "Nothing went wrong"))Nothing went wrongRight ()
Similar to runFailLast, except underlying monad is not restricted to Identity.
Similar to runFailAgg, except underlying monad is not restricted to Identity.
Change the underlying monad with the hoisting function.
Map a function over the underlying representation of the FailT monad.
Map a function over the error type in the FailT monad.
Map a function over the aggregation of errors in the FailT monad. Could be used for example for clearing our all of the aggregated error messages:
runFail (mapErrorsFailT (const []) $ failT "Something went wrong") :: Either String ()Left "No failure reason given"
Same as exceptFailT, but works with any MonadError.
throwErrorFailT (fail "A bad thing" >> pure () :: FailT String (Except FailException) ())ExceptT (Identity (Left FailException"A bad thing"CallStack (from HasCallStack):...
Use the MonadThrow instance to raise a FailException in the underlying monad.
throwFailT (failT "One thing went wrong")*** Exception: FailException"One thing went wrong"...throwFailT (failT "One thing went wrong") :: Maybe ()Nothing
Helpers
3 declarationsLift a operation to the new monad.catchE
Lift a listen operation to the new monad.
Lift a pass operation to the new monad.