Copied from @hysl20's comment at ghc-proposals/ghc-proposals#766 (comment), saved as a Gist for reference (since GitHub PR comment links don't always navigate directly to the comment, e.g. if it's hidden)
I think there is a lightweight alternative that isn't in the wiki and that doesn't require changing the language:
- use an
OPAQUEhelper function to hideunsafePerformIO - require
Typeable a: no risk of having a top-levelforall a. IORef [a]and segfaults - use
HasCallStackto guarantee that each call is unique: avoid CSE of global variables