I’m preparing to release a new small library https://github.com/arybczak/strict-mutable/tree/master/strict-mutable-base that implements API for strict (WHNF) variants of Chan, IORef and MVar for proactive prevention of space leaks (links lead to the source code in the repo).
Basically, pretty much always when I need MVarS or IORefs in my code, I want strict modification, but
- for MVar there are no such functions, so you either always have to write a utility function or remember to use
$!
or similar every time youmodifyMVar
, which is annoying and way too fragile. - for IORef there’s
modifyIORef'
, but again, it’s far too easy to forget the'
and end up with a space leak manifesting itself later.writeIORef
is also too lazy.
I wanted API that
- Guarantees that the data you store in MVar/IORef is always in WHNF.
- Has the simplest structure/deps possible.
Surprisingly there seems to be no package for this. The closest I found are
-
strict-concurrency, but it doesn’t use newtypes over base types (so no (1)) and requires
NFData
, which is IMO too strong. Also, judging from GH activity the package seems abandoned. -
strict-mvar which is almost what I want, but it’s based on
io-classes
(and looks like it got deprecated recently)
The plan is to release strict-mutable-base
, perhaps add a wrapper package for MonadUnliftIO
/MonadBaseControl
and also strict-mutable-stm
for corresponding types in the stm
package, since I need strict variants of these too, just less often.
However, maybe I’m missing something and there already exists such a package and I’m just not aware of it, in such case please let me know. Same if you have any comments about the API, better to take care of potential issues before the first release.