safe-globals: Safe top-level mutable variables which scope like ordinary values
This library provides a way to declare IORef
s, TVar
s, Chan
s, etc.
at the top level of a module.
Declarations are safe. User code does not invoke
unsafePerformIO
or compiler pragmas.Variables are ordinary module-level bindings. Their scope can be controlled through the usual module import/export mechanism. Unrelated code cannot interfere with private variables by guessing some global identifier.
References are statically typed, and polymorphic references are statically forbidden.
The implementation is simple, and closely follows existing common practice.
This library does not prevent the software design problems caused by global state. Rather, it provides some implementation safety for those circumstances where global state really is necessary.
Fundamentally this library just provides Template Haskell macros for the
usual unsafePerformIO
trick, so it is subject to the same caveats. In
particular, linking a module and then loading the same module dynamically
through the GHC API may produce two copies of the same top-level variable.
See the documentation of unsafePerformIO
for additional compiler-specific
requirements.
This library may not work properly on GHC before 7.4, due to a GHC bug: http://hackage.haskell.org/trac/ghc/ticket/5558
[Skip to Readme]
Downloads
- safe-globals-0.1.1.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
Versions [RSS] | 0.1, 0.1.1 |
---|---|
Dependencies | base (>=3 && <5), stm (>=2.1), template-haskell (>=2.4) [details] |
License | BSD-3-Clause |
Author | Keegan McAllister <mcallister.keegan@gmail.com> |
Maintainer | Keegan McAllister <mcallister.keegan@gmail.com> |
Category | Data |
Source repo | head: git clone git://github.com/kmcallister/safe-globals |
Uploaded | by KeeganMcAllister at 2011-12-21T16:50:23Z |
Distributions | |
Reverse Dependencies | 1 direct, 0 indirect [details] |
Downloads | 2413 total (3 in the last 30 days) |
Rating | (no votes yet) [estimated by Bayesian average] |
Your Rating | |
Status | Docs uploaded by user Build status unknown [no reports yet] |