{-# LANGUAGE CPP #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE FunctionalDependencies #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE UndecidableInstances #-}{- |
Module : Control.Monad.Error.Class
Copyright : (c) Michael Weber <michael.weber@post.rwth-aachen.de> 2001,
 (c) Jeff Newbern 2003-2006,
 (c) Andriy Palamarchuk 2006
 (c) Edward Kmett 2012
License : BSD-style (see the file LICENSE)
Maintainer : libraries@haskell.org
Stability : experimental
Portability : non-portable (multi-parameter type classes)
[Computation type:] Computations which may fail or throw exceptions.
[Binding strategy:] Failure records information about the cause\/location
of the failure. Failure values bypass the bound function,
other values are used as inputs to the bound function.
[Useful for:] Building computations from sequences of functions that may fail
or using exception handling to structure error handling.
[Zero and plus:] Zero is represented by an empty error and the plus operation
executes its second argument if the first fails.
[Example type:] @'Either' 'String' a@
The Error monad (also called the Exception monad).
-}{-
 Rendered by Michael Weber <mailto:michael.weber@post.rwth-aachen.de>,
 inspired by the Haskell Monad Template Library from
 Andy Gill (<http://web.cecs.pdx.edu/~andy/>)
-}moduleControl.Monad.Error.Class(Error(..),MonadError (..),liftEither ,)whereimportControl.Monad.Trans.Except(Except,ExceptT)importControl.Monad.Trans.Error(Error(..),ErrorT)importqualifiedControl.Monad.Trans.ExceptasExceptT(throwE,catchE)importqualifiedControl.Monad.Trans.ErrorasErrorT(throwError,catchError)importControl.Monad.Trans.IdentityasIdentityimportControl.Monad.Trans.ListasListimportControl.Monad.Trans.MaybeasMaybeimportControl.Monad.Trans.ReaderasReaderimportControl.Monad.Trans.RWS.LazyasLazyRWSimportControl.Monad.Trans.RWS.StrictasStrictRWSimportControl.Monad.Trans.State.LazyasLazyStateimportControl.Monad.Trans.State.StrictasStrictStateimportControl.Monad.Trans.Writer.LazyasLazyWriterimportControl.Monad.Trans.Writer.StrictasStrictWriterimportControl.Monad.Trans.Class(lift)importControl.Exception(IOException,catch,ioError)importControl.Monad#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 707
importControl.Monad.Instances()#endif
importData.MonoidimportPrelude(Either(..),Maybe(..),either,(.),IO){- |
The strategy of combining computations that can throw exceptions
by bypassing bound functions
from the point an exception is thrown to the point that it is handled.
Is parameterized over the type of error information and
the monad type constructor.
It is common to use @'Either' String@ as the monad type constructor
for an error monad in which error descriptions take the form of strings.
In that case and many other common cases the resulting monad is already defined
as an instance of the 'MonadError' class.
You can also define your own error type and\/or use a monad type constructor
other than @'Either' 'String'@ or @'Either' 'IOError'@.
In these cases you will have to explicitly define instances of the 'MonadError'
class.
(If you are using the deprecated "Control.Monad.Error" or
"Control.Monad.Trans.Error", you may also have to define an 'Error' instance.)
-}class(Monadm )=>MonadError e m |m->ewhere-- | Is used within a monadic computation to begin exception processing.throwError ::e ->m a {- |
 A handler function to handle previous errors and return to normal execution.
 A common idiom is:
 > do { action1; action2; action3 } `catchError` handler
 where the @action@ functions can call 'throwError'.
 Note that @handler@ and the do-block must have the same return type.
 -}catchError ::m a ->(e ->m a )->m a #if __GLASGOW_HASKELL__ >= 707
{-# MINIMALthrowError,catchError#-}#endif
{- |
Lifts an @'Either' e@ into any @'MonadError' e@.
> do { val <- liftEither =<< action1; action2 }
where @action1@ returns an 'Either' to represent errors.
@since 2.2.2
-}liftEither::MonadError e m =>Eithere a ->m a liftEither =eitherthrowError returninstanceMonadError IOExceptionIOwherethrowError =ioErrorcatchError =catch{- | @since 2.2.2 -}instanceMonadError ()MaybewherethrowError ()=NothingcatchError Nothingf =f ()catchErrorx _=x -- ----------------------------------------------------------------------------- Our parameterizable error monadinstanceMonadError e (Eithere )wherethrowError =LeftLeftl `catchError `h =h l Rightr `catchError`_=Rightr instance(Monadm ,Errore )=>MonadError e (ErrorTe m )wherethrowError =ErrorT.throwErrorcatchError =ErrorT.catchError{- | @since 2.2 -}instanceMonadm =>MonadError e (ExceptTe m )wherethrowError =ExceptT.throwEcatchError =ExceptT.catchE-- ----------------------------------------------------------------------------- Instances for other mtl transformers---- All of these instances need UndecidableInstances,-- because they do not satisfy the coverage condition.instanceMonadError e m =>MonadError e (IdentityTm )wherethrowError =lift.throwError catchError =Identity.liftCatchcatchError instanceMonadError e m =>MonadError e (ListTm )wherethrowError =lift.throwError catchError =List.liftCatchcatchError instanceMonadError e m =>MonadError e (MaybeTm )wherethrowError =lift.throwError catchError =Maybe.liftCatchcatchError instanceMonadError e m =>MonadError e (ReaderTr m )wherethrowError =lift.throwError catchError =Reader.liftCatchcatchError instance(Monoidw ,MonadError e m )=>MonadError e (LazyRWS.RWSTr w s m )wherethrowError =lift.throwError catchError =LazyRWS.liftCatchcatchError instance(Monoidw ,MonadError e m )=>MonadError e (StrictRWS.RWSTr w s m )wherethrowError =lift.throwError catchError =StrictRWS.liftCatchcatchError instanceMonadError e m =>MonadError e (LazyState.StateTs m )wherethrowError =lift.throwError catchError =LazyState.liftCatchcatchError instanceMonadError e m =>MonadError e (StrictState.StateTs m )wherethrowError =lift.throwError catchError =StrictState.liftCatchcatchError instance(Monoidw ,MonadError e m )=>MonadError e (LazyWriter.WriterTw m )wherethrowError =lift.throwError catchError =LazyWriter.liftCatchcatchError instance(Monoidw ,MonadError e m )=>MonadError e (StrictWriter.WriterTw m )wherethrowError =lift.throwError catchError =StrictWriter.liftCatchcatchError 

AltStyle によって変換されたページ (->オリジナル) /