base-4.12.0.0: Basic libraries

Copyright(C) 2015 David Luposchainsky
(C) 2015 Herbert Valerio Riedel
LicenseBSD-style (see the file LICENSE)
Maintainerlibraries@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

Control.Monad.Fail

Description

Transitional module providing the MonadFail class and primitive instances.

This module can be imported for defining forward compatible MonadFail instances:

import qualified Control.Monad.Fail as Fail

instance Monad Foo where
  (>>=) = {- ...bind impl... -}

  -- Provide legacy fail implementation for when
  -- new-style MonadFail desugaring is not enabled.
  fail = Fail.fail

instance Fail.MonadFail Foo where
  fail = {- ...fail implementation... -}

See https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail for more details.

Since: base-4.9.0.0

Synopsis

Documentation

class Monad m => MonadFail m 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

Since: base-4.9.0.0

Methods

fail :: String -> m a #

Instances
MonadFail [] #

Since: base-4.9.0.0

Instance details

Defined in Control.Monad.Fail

Methods

fail :: String -> [a] #

MonadFail Maybe #

Since: base-4.9.0.0

Instance details

Defined in Control.Monad.Fail

Methods

fail :: String -> Maybe a #

MonadFail IO #

Since: base-4.9.0.0

Instance details

Defined in Control.Monad.Fail

Methods

fail :: String -> IO a #

MonadFail ReadP #

Since: base-4.9.0.0

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

fail :: String -> ReadP a #

MonadFail ReadPrec #

Since: base-4.9.0.0

Instance details

Defined in Text.ParserCombinators.ReadPrec

Methods

fail :: String -> ReadPrec a #

MonadFail (ST s) #

Since: base-4.11.0.0

Instance details

Defined in GHC.ST

Methods

fail :: String -> ST s a #

MonadFail (ST s) #

Since: base-4.10

Instance details

Defined in Control.Monad.ST.Lazy.Imp

Methods

fail :: String -> ST s a #

MonadFail f => MonadFail (Ap f) #

Since: base-4.12.0.0

Instance details

Defined in Data.Monoid

Methods

fail :: String -> Ap f a #