Control.Monad.Fail (original) (raw)
Description
Transitional module providing the [MonadFail](Control-Monad-Fail.html#t:MonadFail "Control.Monad.Fail") class and primitive instances.
This module can be imported for defining forward compatible[MonadFail](Control-Monad-Fail.html#t:MonadFail "Control.Monad.Fail") instances:
import qualified Control.Monad.Fail as Fail
instance Monad Foo where (>>=) = {- ...bind impl... -}
-- Provide legacy [fail](Control-Monad-Fail.html#v:fail "Control.Monad.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 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](Control-Monad.html#t:Monad "Control.Monad") without a [MonadFail](Control-Monad-Fail.html#t:MonadFail "Control.Monad.Fail") 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](Control-Monad-Fail.html#t:MonadFail "Control.Monad.Fail") should satisfy the following law: fail s should be a left zero for [>>=](Control-Monad.html#v:-62--62--61- "Control.Monad"),
fail s >>= f = fail s
If your [Monad](Control-Monad.html#t:Monad "Control.Monad") is also [MonadPlus](Control-Monad.html#v:MonadPlus "Control.Monad"), a popular definition is
fail _ = mzero
Since: base-4.9.0.0