atomicModifyIORef' strictness

David Feuer david.feuer at gmail.com
Sat Jul 14 01:55:49 UTC 2018


In the process of replacing atomicModifyMutVar#, I noticed that
atomicModifyIORef' is just a little bit lazy:

atomicModifyIORef' ref (\x -> (x + 1, undefined))

will increment the reference and then throw an exception in the calling
thread. We could sometimes avoid creating thunks by changing this, so the
above would install undefined in the IORef as well. For example, suppose I
write

atomicModifyIORef' ref (\x -> (3, x + 5))

This will end up producing a thunk for the second component. That could be
avoided using something like

atomicModifyIORef' ref (\ !x -> (3, x + 5))

but it seems a little surprising to have to do that in a function that
focuses on being strict.

I don't really care too much one way or the other, but I figured I should
point this out and see what you all think.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20180713/f8a0a4e1/attachment.html>


More information about the Libraries mailing list