general-allocate: Exception-safe resource management in more monads

[ apache, control, exceptions, library ] [ Propose Tags ]

Write monad-generic resource-safe code that can be instantiated in both IO and pure contexts.

exceptions provides MonadMask, which generalizes the bracket pattern but only for monads that can catch exceptions (i.e., transformer stacks on top of IO or Either SomeException). resourcet provides MonadResource, which allows for arbitrarily interleaved allocations and releases of resources, but only for MonadUnliftIO. This module provides type-classes for both types of resource allocation which can be properly instantiated at more monads, through the expedient of weakening a requirement which doesn't matter in the cases where it's not met: In monads that can't catch exceptions, release actions will not be called in the case of an exception (asynchronous or otherwise), but in those same monads the entire monadic computation will be terminated by the same exception and so resource management has ended anyway.

See Control.Monad.With for scoped (bracket-style) resource management.

See Control.Monad.Allocate for arbitrary lifetime resource management.

See Data.GeneralAllocate to define values that can be used for allocation in either resource management style.


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],,,,,,,,,,,
Change log
Dependencies base (>=4.14 && <4.15 || >=4.16 && <4.20), containers (>=0.6 && <0.8), exceptions (>=0.10 && <0.11), mtl (>=2.2 && <2.4), primitive (>=0.7 && <0.10), resourcet (>=1.3 && <1.4), safe-exceptions (>=0.1 && <0.2), transformers (>=0.5 && <0.7) [details]
License Apache-2.0
Copyright Coypright 2022 Shea Levy.
Author Shea Levy
Category Control, Exceptions
Bug tracker
Source repo head: git clone
Uploaded by shlevy at 2024-01-13T03:35:06Z
Distributions NixOS:
Reverse Dependencies 3 direct, 4 indirect [details]
Downloads 487 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-01-13 [all 1 reports]