Handle exceptions thrown in IO with fused-effects.
 
 
Go to file
Patrick Thomson 8d2101ae5c Travis is in a separate PR now. 2019-10-15 16:58:52 -04:00
src/Control Fix documentation and merge fallout. 2019-10-14 13:28:21 -04:00
.gitignore Add travis stuff since this is now a more prominent part of the ecosystem. 2019-10-14 13:24:55 -04:00
ChangeLog.md Add travis stuff since this is now a more prominent part of the ecosystem. 2019-10-14 13:24:55 -04:00
LICENSE Extract from parent project. 2019-03-19 10:24:57 -04:00
README.md Add Resource effect and port to fused-effects 1.0. 2019-10-14 13:22:38 -04:00
Setup.hs Extract from parent project. 2019-03-19 10:24:57 -04:00
fused-effects-exceptions.cabal Merge remote-tracking branch 'origin/master' into port-resource-effect-for-1.0 2019-10-14 13:24:28 -04:00
stack.yaml Add real version bound. 2019-04-08 13:14:38 -04:00

README.md

fused-effects-exceptions

Hackage BSD3 license Build status

This package provides two useful effects for handling exceptions thrown from pure code or IO with GHC's Control.Exception.throw function.

Control.Effect.Resource

This effect provides bracket, finally, and onException functions capable of allocating and freeing scarce resources in the presence of GHC's exceptions. It is similar in functionality to the resourcet package.

This effect was included in prior versions of fused-effects, but has been moved to this package due to the surprising interactions it can have with the Control.Carrier.State carriers provided by fused-effects. If you use the ResourceC and StateC effects in conjunction, writes inside a finally block may be discarded, since finally discards the result of its cleanup handler:

λ runM (runResource (runState 'a' (modify (succ @Char) `finally` modify (succ . succ @Char))))
('b', ())

If this behavior is a concern, a Control.Carrier.State.IORef carrier is provided, which fixes this issue given access to a MonadIO constraint. If it is not a concern (such as if the cleanup block is only run for its effects in IO), then the StateC carriers from fused-effects will suffice. For more information about the issues associated with this approach, consult Alexis King's excellent Demystifying MonadBaseControl.

Control.Effect.State

This effect is similar to the MonadCatch and MonadThrow classes provided by the exceptions package. It delegates to catch from Control.Exception. An additional catchSync primitive is provided to handle the common case of catching only synchronous exceptions. Its implementation was extracted from one originally written by Josh Vera.

This effect displays the same behavior associated with Resource in that carriers like Control.Carrier.State.Strict which rely on return types to propagate state may drop state information.