-
Notifications
You must be signed in to change notification settings - Fork 57
Closed
Description
We certainly want generator application to modify the generator strictly, but it's not always reasonable to produce the result strictly. I think applyRandomGenM itself probably shouldn't force the result, but there should be a strict function based on it for implementing, e.g., uniformWord32R. For most RandomGenM instances, the change is trivial. For AtomicGenM, we'd need a half-strict version of atomicModifyIORef. For all vaguely recent GHC versions, it would look like this:
import GHC.IORef (atomicModifyIORef2)
atomicModifyIORefHS :: IORef a -> (a -> (a,b)) -> IO b
atomicModifyIORefHS ref f = do
(_old, (_new, res)) <- atomicModifyIORef2 ref $
\old -> case f old of
r@(!_new, _res) -> r
pure resIt's also possible to implement for older versions, but a bit less efficiently.
Metadata
Metadata
Assignees
Labels
No labels