HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-internal-9.1003.0Haskell2010

GHC.Internal.Control.Monad.Fail

  • 1 class
classclass 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 Control.Monad.>>=,

fail s >>= f  =  fail s

If your Monad is also Control.Monad.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.

Methods

Instances7MonadFail, …
  • MonadFail MaybeDefined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.Fail
  • MonadFail PDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • MonadFail ReadPDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • MonadFail ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • MonadFail IODefined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.Fail
  • MonadFail []Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.Fail
  • MonadFail f => MonadFail (Ap f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid