Discussion: Add unboxed mutable references somewhere sensible

David Feuer david.feuer at gmail.com
Thu Feb 12 00:03:34 UTC 2015


The problem they solve is perhaps not as well known as it should be:

Code that frequently modifies an `STRef Int`, for example, will
typically surprise the programmer by allocating a ton of memory. This
happens because the reference holds a *boxed* Int. Code like

    modifySTRef ref (+1)

will allocate a new Int box every time. To the best of my knowledge,
GHC makes no attempt to figure out if this is actually necessary and
do something about it. The Data.Ref.Unboxed module in the ArrayRef
package attempts to address this, but it doesn't seem to get much
visibility, and its code hasn't been touched since 2009. What can we
do about this?


More information about the Libraries mailing list