Add modifyRef that returns a pure value

This is equivalent to the atomicModifyIORef from Haskell
Looks like this line needs to be updated too.