Control.monad.error.class
the file LICENSE)Maintainerlibraries@haskell.orgStabilityexperimentalPortabilitynon-portable (multi-parameter type classes)Safe HaskellSafeLanguageHaskell98Control.Monad.Error.ClassDescriptionComputation 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).Synopsisclass Error a wherenoMsg :: astrMsg :: String -> aclass Monad m => MonadError e m | m -> e wherethrowError :: e -> m acatchError :: m a -> (e -> m a) -> m aDocumentationclass Error a whereAn exception to be thrown.Minimal complete definition: noMsg or strMsg.Minimal complete definitionNothingMethodsnoMsg :: aCreates an exception without a message. The default implementation is strMsg ""
.strMsg :: String -> aCreates an exception with a message. The default implementation of strMsg s
is noMsg.InstancesError IOExceptionErrorList a => Error [a]A string can be thrown as an error.class Monad m => MonadError e m | m -> e where SourceThe 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
type classes)Safe HaskellSafeLanguageHaskell98Control.Monad.ErrorContentsMonads with error handlingThe ErrorT monad transformerExample 1: Custom Error Data TypeExample 2: Using ErrorT Monad TransformerDescriptionDeprecated: Use Control.Monad.Except insteadComputation 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 https://hackage.haskell.org/package/mtl/docs/Control-Monad-Error-Class.html fails.Example type:Either String a
The Error monad (also called the Exception monad).Synopsisclass Monad m => MonadError e m | m -> e wherethrowError :: e -> m acatchError :: m a -> (e -> m a) -> m aclass Error a wherenoMsg :: astrMsg :: String -> anewtype ErrorT e m a :: * -> (* https://hackage.haskell.org/package/mtl/docs/Control-Monad-Error.html -> *) -> * -> * = ErrorT {runErrorT :: m (Either e a)}runErrorT :: ErrorT e m a -> m (Either e a)mapErrorT :: (m (Either e a) -> n (Either e' b)) -> ErrorT e m a -> ErrorT e' n bmodule Control.Monadmodule Control.Monad.Fixmodule Control.Monad.TransMonads with error handlingclass Monad m => MonadError e m | m -> e where SourceThe 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 https://github.com/purescript/purescript-transformers/blob/master/src/Control/Monad/Error/Class.purs Pulse Graphs Permalink Branch: master Switch branches/tags Branches Tags fundeps master Nothing to show v1.0.0 v1.0.0-rc.2 v1.0.0-rc.1 v0.8.4 v0.8.3 v0.8.2 v0.8.1 v0.8.0 v0.7.2 v0.7.1 v0.7.0-rc.2 v0.7.0-rc.1 v0.6.1 v0.6.0 v0.6.0-rc.2 http://fossies.org/linux/haskell-platform/packages/mtl-2.2.1/Control/Monad/Error/Class.hs v0.6.0-rc.1 v0.5.5 v0.5.4 v0.5.3 v0.5.2 v0.5.1 v0.5.0 v0.4.1 v0.4.0 v0.3.2 v0.3.1 v0.3.0 v0.2.1 v0.2.0 v0.1.2 v0.1.1 v0.1.0 v0.0.6 v0.0.5 v0.0.4 v0.0.3 v0.0.2 v0.0.1 Nothing to show Find file Copy path purescript-transformers/src/Control/Monad/Error/Class.purs Fetching contributors… Cannot retrieve contributors at this time Raw Blame History 57 lines (49 sloc) 1.78 KB -- | This module defines the `MonadError` type class and its instances. module Control.Monad.Error.Class where import Prelude import Data.Maybe (Maybe(..)) import Data.Either (Either(..)) -- | The `MonadError` type class represents those monads which support errors via -- | `throwError` and `catchError`. -- | -- | - `throwError e` throws the error `e` -- | - `catchError x f` calls the error handler `f` if an error is thrown during the -- | evaluation of `x`. -- | -- | An implementation is provided for `ErrorT`, and for other monad transformers -- | defined in this library. -- | -- | Laws: -- | -- | - Left zero: `throwError e >>= f = throwError e` -- | - Catch: `catchError (throwError e) f = f e` -- | - Pure: `catchError (pure a) f = pure a` -- | class Monad m <= MonadError e m where throwError :: forall a. e -> m a catchError :: forall a. m a -> (e -> m a) -> m a -- | This function allows you to provide a predicate for selecting the -- | exceptions that you're interested in, and handle only those exceptons. -- | If the inner computation throws an exception, and the predicate returns -- | Nothing, then the who
has tried to format the requested source page into HTML format using (guessed) Haskell source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field. 1 {-# LANGUAGE CPP #-} 2 {-# LANGUAGE UndecidableInstances #-} 3 4 {- | 5 Module : Control.Monad.Error.Class 6 Copyright : (c) Michael Weber