GHC.Internal.Control.Monad.Fail

ghc-internal-9.1001.0: Basic libraries

Copyright | (C) 2015 David Luposchainsky (C) 2015 Herbert Valerio Riedel
License | BSD-style (see the file LICENSE)
Maintainer | libraries@haskell.org
Stability | provisional
Portability | portable
Safe Haskell | Trustworthy
Language | Haskell2010

GHC.Internal.Control.Monad.Fail

Description

Synopsis

- class Monad m => MonadFail (m :: Type -> Type) where
  - fail :: String -> m a

# Documentation

class Monad m => MonadFail (m :: Type -> Type) where Source #

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

Methods

fail :: String -> m a Source #

#### Instances

Instances details

MonadFail ReadP Source # | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadP Methods fail :: String -> ReadP a Source #
MonadFail ReadPrec Source # | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadPrec Methods fail :: String -> ReadPrec a Source #
MonadFail IO Source # | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Control.Monad.Fail Methods fail :: String -> IO a Source #
MonadFail Maybe Source # | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Control.Monad.Fail Methods fail :: String -> Maybe a Source #
MonadFail [] Source # | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Control.Monad.Fail Methods fail :: String -> [a] Source #
MonadFail f => MonadFail (Ap f) Source # | @since base-4.12.0.0
Instance details Defined in GHC.Internal.Data.Monoid Methods fail :: String -> Ap f a Source #