| Copyright | (C) 2026 - Eitan Chatav |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Eitan Chatav <eitan.chatav@gmail.com> |
| Stability | provisional |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Control.Monad.Fail.Try
Description
Synopsis
- class (MonadFail m, MonadPlus m, Filterable m, forall x. BackusNaurForm (m x)) => MonadTry (m :: Type -> Type) where
- try :: m a -> m a
- class Monad m => MonadFail (m :: Type -> Type) where
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- class Applicative f => Alternative (f :: Type -> Type) where
- class Functor f => Filterable (f :: Type -> Type) where
MonadTry
class (MonadFail m, MonadPlus m, Filterable m, forall x. BackusNaurForm (m x)) => MonadTry (m :: Type -> Type) where Source #
MonadTry is a failure handling interface, with fail & try
and redundant alternation & filtration operators.
empty = mzero
(<|>) = mplus
filter = mfilter
MonadTry also supports the BackusNaurForm interface
for tracing failures and the following invariant should hold.
fail label = rule label empty
Minimal complete definition
Nothing
Methods
A handler for failures.
Used for backtracking state on failure in
Parsector.
MonadFail
class Monad m => MonadFail (m :: Type -> Type) where #
When a value is bound in do-notation, the pattern on the left
hand side of <- might not match. In this case, this class
provides a function to recover.
A Monad without a MonadFail instance may only be used in conjunction
with pattern that always match, such as newtypes, tuples, data types with
only a single data constructor, and irrefutable patterns (~pat).
Instances of MonadFail should satisfy the following law: fail s should
be a left zero for >>=,
fail s >>= f = fail s
If your Monad is also MonadPlus, a popular definition is
fail _ = mzero
fail s should be an action that runs in the monad itself, not an
exception (except in instances of MonadIO). In particular,
fail should not be implemented in terms of error.
Since: base-4.9.0.0
Instances
MonadPlus
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Monads that also support choice and failure.
Minimal complete definition
Nothing
Methods
The identity of mplus. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>)
Instances
| MonadPlus STM | Takes the first non- Since: base-4.3.0.0 |
| MonadPlus P | Since: base-2.1 |
Defined in Text.ParserCombinators.ReadP | |
| MonadPlus ReadP | Since: base-2.1 |
| MonadPlus ReadPrec | Since: base-2.1 |
| MonadPlus Seq | |
| MonadPlus IO | Takes the first non-throwing Since: base-4.9.0.0 |
| MonadPlus Deque | |
| MonadPlus Array | |
| MonadPlus SmallArray | |
Defined in Data.Primitive.SmallArray | |
| MonadPlus Vector | |
Defined in Data.Vector | |
| MonadPlus Vector | |
Defined in Data.Vector.Strict | |
| MonadPlus Maybe | Picks the leftmost Since: base-2.1 |
| MonadPlus [] | Combines lists by concatenation, starting from the empty list. Since: base-2.1 |
| (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow | |
| MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus v => MonadPlus (Free v) | This violates the MonadPlus laws, handle with care. |
| MonadPlus m => MonadPlus (Yoneda m) | |
| MonadPlus (ReifiedFold s) | |
Defined in Control.Lens.Reified | |
| Monad m => MonadPlus (MaybeT m) | |
| MonadPlus m => MonadPlus (Kleisli m a) | Since: base-4.14.0.0 |
| MonadPlus f => MonadPlus (Ap f) | Since: base-4.12.0.0 |
| MonadPlus f => MonadPlus (Alt f) | Since: base-4.8.0.0 |
| MonadPlus f => MonadPlus (Rec1 f) | Since: base-4.9.0.0 |
| MonadPlus (bi a) => MonadPlus (Biap bi a) | |
| Categorized (Item s) => MonadPlus (Parsector s a) Source # | |
| (Functor f, MonadPlus m) => MonadPlus (FreeT f m) | |
| (Monoid w, Functor m, MonadPlus m) => MonadPlus (AccumT w m) | |
| (Monad m, Monoid e) => MonadPlus (ExceptT e m) | |
| MonadPlus m => MonadPlus (IdentityT m) | |
| MonadPlus m => MonadPlus (ReaderT r m) | |
| MonadPlus m => MonadPlus (SelectT r m) | |
| MonadPlus m => MonadPlus (StateT s m) | |
| MonadPlus m => MonadPlus (StateT s m) | |
| (Functor m, MonadPlus m) => MonadPlus (WriterT w m) | |
| (Monoid w, MonadPlus m) => MonadPlus (WriterT w m) | |
| (Monoid w, MonadPlus m) => MonadPlus (WriterT w m) | |
| MonadPlus m => MonadPlus (Reverse m) | Derived instance. |
| (MonadPlus f, MonadPlus g) => MonadPlus (Product f g) | Since: base-4.9.0.0 |
| (MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) | Since: base-4.9.0.0 |
| (Alternative m, Monad m) => MonadPlus (Parsor s m a) Source # | |
| (Alternative f, Monad f) => MonadPlus (Printor s f a) Source # | |
| MonadPlus f => MonadPlus (Star f a) | |
| MonadPlus f => MonadPlus (M1 i c f) | Since: base-4.9.0.0 |
| MonadPlus m => MonadPlus (Joker m a) Source # | |
| (Functor m, MonadPlus m) => MonadPlus (RWST r w s m) | |
| (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) | |
| (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) | |
Alternative
class Applicative f => Alternative (f :: Type -> Type) where #
A monoid on applicative functors.
If defined, some and many should be the least solutions
of the equations:
Methods
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
Filterable
class Functor f => Filterable (f :: Type -> Type) where #
Like Functor, but you can remove elements instead of updating them.
Formally, the class Filterable represents a functor from Kleisli Maybe to Hask.
A definition of mapMaybe must satisfy the following laws:
Methods
mapMaybe :: (a -> Maybe b) -> f a -> f b #
Like mapMaybe.
catMaybes :: f (Maybe a) -> f a #