|      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ None Safe-Inferredhlike ErrorT, but ExceptionalT is the better name in order to distinguish from real (programming) errors Like ?, but explicitly intended for handling of exceptional results. In contrast to  we do not support . Calling  in the  monad is an error. DThis way, we do not require that an exception can be derived from a , <yet, we require no constraint on the exception type at all. useful in connection with  Counterpart to  for . +If you are sure that the value is always a  &you can tell that the run-time system thus making your program lazy. -However, try to avoid this function by using  and friends,  since this function is partial. see * see * see * see  %7If the enclosed monad has custom exception facilities, "they could skip the cleanup code. EMake sure, that this cannot happen by choosing an appropriate monad. (,Repeat an action until an exception occurs. Initialize the result with empty and add new elements using cons (e.g. [] and (:)). @The exception handler decides whether the terminating exception is re-raised () or catched (). *0This combines two actions similar to Applicative's  *. :The result action fails if one of the input action fails, but both actions are executed. /E.g. consider a compiler that emits all errors $that can be detected independently, 6but eventually aborts if there is at least one error. The exception type e might be a list type, or an Endo" type that implements a difflist. !Same restrictions applies as for #instance MonadFix (Exceptional e a). 4I think it is not a good idea to use this instance, maybe we shoul remove it. #It expects that the constructor is  'and the result is undefined otherwise. &But if the constructor must always be ,  why using  then, at all? 7  !"#$%&'(exception handler cons function  emptyatomic action to repeat )exception handler atomic action to repeat *+  !"#$%&'()*+  !"#$%&'()*3  !"#$%&'()* Safe-Inferred+'In contrast to synchronous exceptions, 9the asynchronous monad transformer is not quite a monad. You must use the  interface or R instead. .GContains a value and a reason why the computation of the value of type a was terminated. Imagine a5 as a list type, and an according operation like the  operation. If the exception part is 0 then the value could be constructed regularly. If the exception part is 5 then the value could not be constructed completely. (However you can read the result of type a lazily, 3even if an exception occurs while it is evaluated. $If you evaluate the exception part, 8then the result value is certainly computed completely. #However, we cannot provide general  functionality @due to the very different ways of combining the results of type a. NIt is recommended to process the result value in an application specific way, Iand after consumption of the result, throw a synchronous exception using 7. 0Maybe in the future we provide a monad instance Wwhich considers subsequent actions as simultaneous processes on a lazy data structure. 2/Create an exceptional value without exception. 3,Create an exceptional value with exception. 8+I think in most cases we want throwMonoid, thus we can replace 8 by 9. :#You might use an exception of type Maybe e in V in order to stop the loop. 'After finishing the loop you will want  to turn the Nothing exception into a success. #This is achieved by this function. ;GThis is an example for application specific handling of result values. *Assume you obtain two lazy lists say from  $and you want to zip their contents. 1If one of the stream readers emits an exception, we quit with that exception. CIf both streams have throw an exception at the same file position, 1the exception of the first stream is propagated. <GThis is an example for application specific handling of result values. *Assume you obtain two lazy lists say from  'and you want to append their contents. ,If the first stream ends with an exception, this exception is kept &and the second stream is not touched. .If the first stream can be read successfully, (the second one is appended until stops. < is less strict than the  method  instance. ?*construct Exceptional constructor lazily BTI consider both actions to process the data simultaneously through lazy evaluation. CIf the second one fails too, it must have encountered an exception ?in the data that was successfully emitted by the first action, Aand thus the exception of the second action is probably earlier. MWe cannot check in general whether the two exception occur at the same time, We.g. the second one might occur since the first occured and left an invalid structure. EIn this case we should emit the first exception, not the second one. HBecause of this I expect that this function is not particularly useful. COtherwise it could be used as bind operation for a monad instance. DIs there a better name? EFoldable= instance would allow to strip off the exception too easily. I like the methods of  Traversable, but  Traversable instance requires Foldable instance. I?Consider a file format consisting of a header and a data body. 3The header can only be used if is read completely. 6Its parsing might stop with an synchronous exception. KThe data body can also be used if it is truncated by an exceptional event. 0This is expressed by an asynchronous exception. ,A loader for this file format can thus fail 0by a synchronous and an asynchronous exception. LSurprisingly, both orders of nesting these two kinds of exceptional actions are equally expressive. UThis function converts to the form where the synchronous exception is the outer one. This is a specialisation of H and friends. Msee ? RThe monadic bind operation. 8It cannot be made an instance of the Monad class method (>>=) )since it requires a default return value  in case the first action fails. !We get this default value by the  method . UHRepeat an action with synchronous exceptions until an exception occurs. %Combine all atomic results using the bind function.  It may be  cons = (:) and  empty = [] for b being a list type. The defer function may be id or unsafeInterleaveIO for lazy read operations. 5The exception is returned as asynchronous exception. V!We advise to use the Endo Monoid :when you want to read a series of characters into a list. 2This means you use the difference lists technique 0in order to build the list, which is efficient.  & import Data.Monoid (Endo, appEndo, ) " import Control.Exception (try, ) > import qualified Control.Monad.Exception.Synchronous as Sync  t fmap (flip appEndo []) $ manyMonoidT (fromSynchronousMonoidT $ fmap (Endo . (:)) $ Sync.fromEitherT $ try getChar) 2If you want Lazy IO you must additionally convert getChar to LazyIO monad. WScan x using the decons function Land run an action with synchronous exceptions for each element fetched from x. <Each invocation of an element action may stop this function due to an exception. 5If all element actions can be performed successfully *and if there is an asynchronous exception Cthen at the end this exception is raised as synchronous exception. decons function might be Data.List.HT.viewL. 4 must be strict in order to fulfill the Monoid laws mappend mempty a = a and mappend a mempty = a for  a=undefined. 2+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUdefer function cons function  emptyatomic action to repeat Vatomic action to repeat Wdecons function 1action that is run for each element fetched from x value x of type b with asynchronous exception -+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVW-./0123456789:;<=>?@ABCDEFGHIJ+,-KLMNOPQRUVWST-+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVW Safe-InferredContains a value and Kpossibly warnings that were generated while the computation of that value. #Convert an exception to a warning.  None Currently 5 calls the exception handler with a full call stack. Since  handles exceptions locally Dit may however clear the call stack before calling the inner action Dand a re-throw should append the inner call stack to the outer one. JFor this semantics, a difference list would be more efficient for labels. 7If the enclosed monad has custom exception facilities, "they could skip the cleanup code. EMake sure, that this cannot happen by choosing an appropriate monad.   None;Users of the library may define new instances of MonadSIO, Kbut monads other than SIO may not make the absence of exceptions explicit. 8It is important however, that we do not make the method  public, since this would allow users the unsafe conversion from IO to SIO. 9Maybe we should not be so picky about exceptional monads %within exception monad transformers.  A monad like +ExceptionalT e0 (StateT s (Exceptional e1)) may be useful for distinction of non-fatal exceptions e0 that can maintain the state s and fatal exceptions e1. that prevent generation of an updated state. An I/O action of type # cannot skip following SIO actions )as a result of exceptional outcomes like "File not found".  However an  can well break the program.   None None Safe-InferredX'In contrast to synchronous exceptions, 9the asynchronous monad transformer is not quite a monad. You must use the  interface or  instead. [GContains a value and a reason why the computation of the value of type a was terminated. Imagine a5 as a list type, and an according operation like the  operation. If the exception part is 0 then the value could be constructed regularly. If the exception part is 5 then the value could not be constructed completely. (However you can read the result of type a lazily, 3even if an exception occurs while it is evaluated. $If you evaluate the exception part, 8then the result value is certainly computed completely. #However, we cannot provide general  functionality @due to the very different ways of combining the results of type a. NIt is recommended to process the result value in an application specific way, Iand after consumption of the result, throw a synchronous exception using d. 0Maybe in the future we provide a monad instance Wwhich considers subsequent actions as simultaneous processes on a lazy data structure. 'This variant has lazy combinators like . /This implies that some laws are not fulfilled, +but in practice it saves you some calls to l. _/Create an exceptional value without exception. `,Create an exceptional value with exception. e+I think in most cases we want throwMonoid, thus we can replace e by f. g#You might use an exception of type Maybe e in  in order to stop the loop. 'After finishing the loop you will want  to turn the Nothing exception into a success. #This is achieved by this function. hGThis is an example for application specific handling of result values. *Assume you obtain two lazy lists say from  $and you want to zip their contents. 1If one of the stream readers emits an exception, we quit with that exception. CIf both streams have throw an exception at the same file position, 1the exception of the first stream is propagated. iGThis is an example for application specific handling of result values. *Assume you obtain two lazy lists say from  'and you want to append their contents. ,If the first stream ends with an exception, this exception is kept &and the second stream is not touched. .If the first stream can be read successfully, (the second one is appended until stops. i is less strict than the  method  instance. l*construct Exceptional constructor lazily oTI consider both actions to process the data simultaneously through lazy evaluation. CIf the second one fails too, it must have encountered an exception ?in the data that was successfully emitted by the first action, Aand thus the exception of the second action is probably earlier. MWe cannot check in general whether the two exception occur at the same time, We.g. the second one might occur since the first occured and left an invalid structure. EIn this case we should emit the first exception, not the second one. HBecause of this I expect that this function is not particularly useful. COtherwise it could be used as bind operation for a monad instance. qIs there a better name? rFoldable= instance would allow to strip off the exception too easily. I like the methods of  Traversable, but  Traversable instance requires Foldable instance. v?Consider a file format consisting of a header and a data body. 3The header can only be used if is read completely. 6Its parsing might stop with an synchronous exception. KThe data body can also be used if it is truncated by an exceptional event. 0This is expressed by an asynchronous exception. ,A loader for this file format can thus fail 0by a synchronous and an asynchronous exception. LSurprisingly, both orders of nesting these two kinds of exceptional actions are equally expressive. UThis function converts to the form where the synchronous exception is the outer one. This is a specialisation of u and friends. zsee l The monadic bind operation. 8It cannot be made an instance of the Monad class method (>>=) )since it requires a default return value  in case the first action fails. !We get this default value by the  method . HRepeat an action with synchronous exceptions until an exception occurs. %Combine all atomic results using the bind function.  It may be  cons = (:) and  empty = [] for b being a list type. The defer function may be id or unsafeInterleaveIO for lazy read operations. 5The exception is returned as asynchronous exception. !We advise to use the Endo Monoid :when you want to read a series of characters into a list. 2This means you use the difference lists technique 0in order to build the list, which is efficient.  & import Data.Monoid (Endo, appEndo, ) " import Control.Exception (try, ) > import qualified Control.Monad.Exception.Synchronous as Sync  t fmap (flip appEndo []) $ manyMonoidT (fromSynchronousMonoidT $ fmap (Endo . (:)) $ Sync.fromEitherT $ try getChar) 2If you want Lazy IO you must additionally convert getChar to LazyIO monad. Scan x using the decons function Land run an action with synchronous exceptions for each element fetched from x. <Each invocation of an element action may stop this function due to an exception. 5If all element actions can be performed successfully *and if there is an asynchronous exception Cthen at the end this exception is raised as synchronous exception. decons function might be Data.List.HT.viewL. fmap (f.g) = fmap f . fmap g The law  fmap id = id 1requires that we match the constructor strictly. Strict matching / fmap id undefined = undefined = id undefined Lazy matching 6 fmap id undefined = Exceptional undefined undefined  /= undefined = id undefined 4 must be strict in order to fulfill the Monoid laws mappend mempty a = a and mappend a mempty = a for  a=undefined. 2XYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~defer function cons function  emptyatomic action to repeat atomic action to repeat decons function 1action that is run for each element fetched from x value x of type b with asynchronous exception -XYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~-[\]^_`abcdefghijklmnopqrstuvwXYZxyz{|}~-XYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ Safe-Inferred-XYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ None This calls unsafeInterleaveIO. Maybe we should also attach unsafe to this function name? .We should use the LazyIO type and manyT here.    !"#$%&'()*+,-./0123456  789:;<=>?@ABCDEFGHIJKLMN+,-OPQRST5U  789:;<=>?@ABCDEFGHIJKLMN+,-OPQRST5UVVWXXYZ[\]^_`abcdefghfijfikfglmnfopfoqrstuvwxyz{f|}f~fif|f|x{M017`.  f   f  fi{x explicit-exception-0.1.7.1#Control.Monad.Exception.Synchronous+Control.Monad.Exception.Asynchronous.Strict)Control.Monad.Exception.Asynchronous.LazyControl.Monad.Label$Control.Monad.Exception.AsynchronouscontinueControl.Monad.Exception.WarningControl.Monad.Exception.LabelSystem.IO.StraightSystem.IO.Exception.FileSystem.IO.Exception.BinaryFileSystem.IO.Exception.TextFile ExceptionalTrunExceptionalT Exceptional ExceptionSuccess fromMaybe fromEithertoMaybetoEither toExitCode fromExitCodegetExceptionNullswitchforce mapExceptionmapExceptionalthrowassertcatchresolvemerge fromMaybeTtoMaybeT fromErrorTtoErrorT fromEitherT toEitherT toExitCodeT fromExitCodeTswitchTforceT mapExceptionTmapExceptionalTthrowTassertTcatchTbracketTresolveTtryTmanyT manyMonoidTmergeT exceptionresultpurebrokenfromSynchronousfromSynchronousNullfromSynchronousMonoid toSynchronous throwMonoid eatNothingzipWithappend maybeAbortsimultaneousBindsimultaneousBindM sequenceFtraverse sequenceAmapMsequenceswapToSynchronousAsynchronousswapToAsynchronousSynchronousfromSynchronousTfromSynchronousMonoidT throwMonoidT eatNothingTbindTappendM continueMmanySynchronousTprocessToSynchronousT_LabelT runLabelPrivTLabel runLabelPrivrunLabelasklocal fmapReaderT pureReaderT apReaderT runLabelTaskTlocalT$fApplicativeLabelT$fFunctorLabelT$fApplicativeLabelbase Data.EitherEitherGHC.BasefailStringeither mergeLazy _mergeStrict Data.MaybeJustNothing$fMonadFixExceptionalT$fMonadFixExceptional _assertMaybeT$fMonadTransExceptionalT$fMonadExceptionalT$fApplicativeExceptionalT$fFunctorExceptionalT$fMonadExceptional$fApplicativeExceptional$fFunctorExceptional Data.MonoidMonoid System.IOreadFileMonadmappendmempty$fMonoidExceptionalcontinueMPlain$fMonoidExceptionalTWarnable fromException WarnableT runWarnableTfromExceptionNull toExceptionwarnwarnT$fMonadWarnableT$fApplicativeWarnableT$fFunctorWarnableT$fMonadWarnable$fApplicativeWarnable$fFunctorWarnableLabeledExceptionalTrunLabeledExceptionalTLabeledExceptionlabelslabelT stripLabelTdecorateLabelT getLabels$fMonadTransLabeledExceptionalTMonadSIOtoSIOSIOGHC.ErrerrorContainsIOExceptionfromIOExceptionsioToIOioToExceptionalSIOunsafeInterleaveSIO$fMonadIOExceptionalT $fContainsIOExceptionIOException $fMonadSIOSIOGHC.IO.Exception IOExceptionEIOcloseopenwithgetByteputBytefmapgetContentsAsynchronousgetChargetContentsSynchronousputChar