h"=;\      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopq0(C) Edward Kmett 2013-2015, (c) Google Inc. 2012 BSD-style (see the file LICENSE)Edward Kmett  experimental non-portable Trustworthy>5( exceptionsGeneralized version of r exceptionsA   computation may either succeed with a value, abort with an exception, or abort for some other reason. For example, in  ExceptT e IO you can use  to abort with an exception ( ) or  to abort with a value of type e ( ).  exceptionsA class for monads which provide for the ability to account for all possible exit points from a computation, and to mask asynchronous exceptions. Continuation-based monads are invalid instances of this class.4Instances should ensure that, in the following code: fg = f `finally` g The action g, is called regardless of what occurs within f1, including async exceptions. Some monads allow f to abort the computation via other effects than throwing an exception. For simplicity, we will consider aborting and throwing an exception to be two forms of "throwing an error".If f and g* both throw an error, the error thrown by fg depends on which errors we're talking about. In a monad transformer stack, the deeper layers override the effects of the inner layers; for example, ExceptT e1 (Except e2) a represents a value of type Either e2 (Either e1 a), so throwing both an e1 and an e2 will result in Left e2. If f and g both throw an error from the same layer, instances should ensure that the error from g wins.Effects other than throwing an error are also overriden by the deeper layers. For example, StateT s Maybe a represents a value of type s -> Maybe (a, s), so if an error thrown from f causes this function to return Nothing", any changes to the state which f. also performed will be erased. As a result, g% will see the state as it was before f. Once g completes, f's error will be rethrown, so g' state changes will be erased as well. This is the normal interaction between effects in a monad transformer stack. By contrast,  /https://hackage.haskell.org/package/lifted-base lifted-base's version of & always discards all of g's non-IO effects, and g never sees any of f's non-IO effects, regardless of the layer ordering and regardless of whether f throws an error. This is not the result of interacting effects, but a consequence of MonadBaseControl 's approach.  exceptionsRuns an action with asynchronous exceptions disabled. The action is provided a method for restoring the async. environment to what it was at the   call. See Control.Exception's s. exceptionsLike  8, but the masked computation is not interruptible (see Control.Exception's t. WARNING: Only use if you need to mask exceptions around an interruptible operation AND you can guarantee the interruptible operation will only block for a short period of time. Otherwise you render the program/thread unresponsive and/or unkillable.  exceptionsA generalized version of $ which uses  to distinguish the different exit cases, and returns the values of both the use and release actions. In practice, this extra information is rarely needed, so it is often more convenient to use one of the simpler functions which are defined in terms of this one, such as $, &, #, and '.This function exists because in order to thread their effects through the execution of $6, monad transformers need values to be threaded from use to release and from release to the output value.NOTE This method was added in version 0.9.0 of this library. Previously, implementation of functions like $ and &" in this module were based on the   and  functions only, disallowing some classes of tranformers from having  MonadMask8 instances (notably multi-exit-point transformers like u). If you are a library author, you'll now need to provide an implementation for this method. The StateT5 implementation demonstrates most of the subtleties: generalBracket acquire release use = StateT $ s0 -> do ((b, _s2), (c, s3)) <- generalBracket (runStateT acquire s0) ((resource, s1) exitCase -> case exitCase of ExitCaseSuccess (b, s2) -> runStateT (release resource (ExitCaseSuccess b)) s2 -- In the two other cases, the base monad overrides use3's state -- changes and the state reverts to s1. ExitCaseException e -> runStateT (release resource (ExitCaseException e)) s1 ExitCaseAbort -> runStateT (release resource ExitCaseAbort) s1 ) ((resource, s1) -> runStateT (use resource) s1) return ((b, c), s3) The  StateT s m implementation of generalBracket delegates to the m implementation of generalBracket. The acquire, use, and release arguments given to StateT+'s implementation produce actions of type  StateT s m a,  StateT s m b, and  StateT s m c. In order to run those actions in the base monad, we need to call  runStateT(, from which we obtain actions of type m (a, s), m (b, s), and m (c, s). Since each action produces the next state, it is important to feed the state produced by the previous action to the next action.In the   case, the state starts at s0, flows through acquire to become s1, flows through use to become s2, and finally flows through release to become s3. In the other two cases, release does not receive the value s2;, so its action cannot see the state changes performed by use. This is fine, because in those two cases, an error was thrown in the base monad, so as per the usual interaction between effects in a monad transformer stack, those state changes get reverted. So we start from s1 instead. Finally, the m implementation of generalBracket returns the pairs (b, s) and (c, s)$. For monad transformers other than StateT, this will be some other type representing the effects and values performed and returned by the use and release! actions. The effect part of the use result, in this case _s2, usually needs to be discarded, since those effects have already been incorporated in the release action.?The only effect which is intentionally not incorporated in the release action is the effect of throwing an error. In that case, the error must be re-thrown. One subtlety which is easy to miss is that in the case in which use and release% both throw an error, the error from release6 should take priority. Here is an implementation for ExceptT$ which demonstrates how to do this. generalBracket acquire release use = ExceptT $ do (eb, ec) <- generalBracket (runExceptT acquire) (eresource exitCase -> case eresource of Left e -> return (Left e) -- nothing to release, acquire didn't succeed Right resource -> case exitCase of ExitCaseSuccess (Right b) -> runExceptT (release resource (ExitCaseSuccess b)) ExitCaseException e -> runExceptT (release resource (ExitCaseException e)) _ -> runExceptT (release resource ExitCaseAbort)) (either (return . Left) (runExceptT . use)) return $ do -- The order in which we perform those two v effects determines -- which error will win if they are both w!s. We want the error from -- release3 to win. c <- ec b <- eb return (b, c)  exceptionsA class for monads which allow exceptions to be caught, in particular exceptions which were thrown by .(Instances should obey the following law: catch (throwM e) f = f e1Note that the ability to catch an exception does not guarantee that we can deal with all possible exit points from a computation. Some monads, such as continuation-based stacks, allow for more than just a success/failure strategy, and therefore catch cannot be used by those monads to properly implement a function such as finally. For more information, see  . exceptionsProvide a handler for exceptions thrown during execution of the first action. Note that type of the type of the argument to the handler will constrain which exceptions are caught. See Control.Exception's x. exceptions5A class for monads in which exceptions may be thrown.(Instances should obey the following law: throwM e >> x = throwM eIn other words, throwing an exception short-circuits the rest of the monadic computation. exceptionsThrow an exception. Note that this throws when this action is run in the monad m5, not when it is applied. It is a generalization of Control.Exception's y.Should satisfy the law: throwM e >> f = throwM e exceptionsLike  , but does not pass a restore action to the argument. exceptionsLike , but does not pass a restore action to the argument. exceptionsCatches all exceptions, and somewhat defeats the purpose of the extensible exception system. Use sparingly.NOTE This catches all  exceptions, but if the monad supports other ways of aborting the computation, those other kinds of errors will not be caught. exceptions Catch all z (eqv.  IOException) exceptions. Still somewhat too general, but better than using . See ' for an easy way of catching specific zs based on the predicates in System.IO.Error. exceptionsCatch exceptions only if they pass some predicate. Often useful with the predicates for testing z values in System.IO.Error. exceptionsA more generalized way of determining which exceptions to catch at run time. exceptionsFlipped . See Control.Exception's {. exceptionsFlipped  exceptionsFlipped  exceptionsFlipped  exceptionsFlipped . See Control.Exception's |. exceptions Similar to , but returns an v result. See Control.Exception's .  exceptions A variant of  that takes an exception predicate to select which exceptions are caught. See Control.Exception's }! exceptions+Catches different sorts of exceptions. See Control.Exception's ~" exceptionsRun an action only if an exception is thrown in the main action. The exception is not caught, simply rethrown.NOTE The action is only run if an  exception is thrown. If the monad supports other ways of aborting the computation, the action won't run if those other kinds of errors are thrown. See #.#  exceptionsRun an action only if an error is thrown in the main action. Unlike ", this works with every kind of error, not just exceptions. For example, if f is an u! computation which aborts with a w, the computation  onError f g will execute g, while onException f g will not.This distinction is only meaningful for monads which have multiple exit points, such as Except and . For monads that only have a single exit point, there is no difference between " and #, except that # has a more constrained type.$ exceptionsGeneralized abstracted pattern of safe resource acquisition and release in the face of errors. The first action "acquires" some value, which is "released" by the second action at the end. The third action "uses" the value and its result is the result of the $.If an error is thrown during the use, the release still happens before the error is rethrown.=Note that this is essentially a type-specialized version of . This function has a more common signature (matching the signature from Control.Exception6), and is often more convenient to use. By contrast,  is more expressive, allowing us to implement other functions like '.% exceptions Version of $ without any value being passed to the second and third actions.& exceptionsPerform an action with a finalizer action that is run, even if an error occurs.' exceptionsLike $, but only performs the final action if an error is thrown by the in-between computation.) exceptions&Throws exceptions into the base monad.* exceptions&Throws exceptions into the base monad.+ exceptions&Throws exceptions into the base monad.< exceptions'Catches exceptions from the base monad.= exceptions'Catches exceptions from the base monad.> exceptions'Catches exceptions from the base monad.H exceptionsK  exceptionsM  exceptionsV exceptions exceptionsacquire some resource exceptions?release the resource, observing the outcome of the inner action exceptions)inner action to perform with the resource(  !"#$%&'(  ! "#$%&'0(C) Edward Kmett 2013-2015, (c) Google Inc. 2012 BSD-style (see the file LICENSE)Edward Kmett  experimental non-portable Trustworthy >;$[ exceptionsAdd  handling abilities to a . This should never be used in combination with  . Think of [ as an alternative base monad for use with mocking code that solely throws exceptions via . Note: that 0 monad has these abilities already, so stacking [ on top of it does not add any value and can possibly be confusing:(error "Hello!" :: IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)Hello!runCatchT $ (error "Hello!" :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)*** Exception: Hello!runCatchT $ (throwM (ErrorCall "Hello!") :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)Hello!_ exceptions7Map the unwrapped computation using the given function. ] (_ f m) = f (] m)d exceptionsNote: This instance is only valid if the underlying monad has a single exit point! For example, IO or Either$ would be invalid base monads, but Reader or State would be acceptable..   !"#$%&'Z[\]^_[\]Z^_       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`aabcdefghijklmnopqrstuvwwxyz{z|ww}~!%&'xexceptions-0.10.4Control.Monad.CatchControl.Monad.Catch.PureControl.Monad.Trans.ExceptthrowEControl.ExceptiontrybaseGHC.Exception.Type SomeExceptiondisplayException fromException toException ExceptionHandlerExitCaseExitCaseSuccessExitCaseException ExitCaseAbort MonadMaskmaskuninterruptibleMaskgeneralBracket MonadCatchcatch MonadThrowthrowMmask_uninterruptibleMask_catchAll catchIOErrorcatchIf catchJusthandle handleIOError handleAllhandleIf handleJusttryJustcatches onExceptiononErrorbracketbracket_finallybracketOnError$fMonadThrowContT$fMonadThrowExceptT$fMonadThrowErrorT$fMonadThrowMaybeT$fMonadThrowListT$fMonadThrowRWST$fMonadThrowRWST0$fMonadThrowWriterT$fMonadThrowWriterT0$fMonadThrowReaderT$fMonadThrowStateT$fMonadThrowStateT0$fMonadThrowIdentityT$fMonadThrowEither$fMonadThrowSTM$fMonadThrowST$fMonadThrowIO $fMonadThrowQ$fMonadThrowMaybe$fMonadThrow[]$fMonadCatchExceptT$fMonadCatchErrorT$fMonadCatchMaybeT$fMonadCatchListT$fMonadCatchRWST$fMonadCatchRWST0$fMonadCatchWriterT$fMonadCatchWriterT0$fMonadCatchReaderT$fMonadCatchStateT$fMonadCatchStateT0$fMonadCatchIdentityT$fMonadCatchEither$fMonadCatchSTM$fMonadCatchIO$fMonadMaskExceptT$fMonadMaskErrorT$fMonadMaskMaybeT$fMonadMaskRWST$fMonadMaskRWST0$fMonadMaskWriterT$fMonadMaskWriterT0$fMonadMaskReaderT$fMonadMaskStateT$fMonadMaskStateT0$fMonadMaskIdentityT$fMonadMaskEither $fMonadMaskIO$fFunctorHandler$fShowExitCaseCatchCatchT runCatchTrunCatch mapCatchT$fMonadRWSrwsCatchT$fMonadWriterwCatchT$fMonadReadereCatchT$fMonadStatesCatchT$fMonadMaskCatchT$fMonadCatchCatchT$fMonadThrowCatchT$fMonadIOCatchT$fMonadTransCatchT$fMonadPlusCatchT$fAlternativeCatchT$fTraversableCatchT$fFoldableCatchT$fMonadFixCatchT$fMonadFailCatchT $fMonadCatchT$fApplicativeCatchT$fFunctorCatchTGHC.IOtransformers-0.5.6.2ExceptT Data.EitherEitherLeftthrowIOGHC.IO.ExceptionIOErrorControl.Exception.BaseControl.Monad.Trans.MaybeMaybeTGHC.BaseMonadghc-prim GHC.TypesIO