Current interface has a way of generating values in IO with randomIO. @Shimuuar pointed out that it could be useful to provide interface for such generator.
There are a couple of choices we can make here. We could just as before wrap pure StdGen in an IORef, but a better choice would be to use PrimMonad
GenPrim
Creating a more general GenPrim s by wrapping StdGen in a MutVar that can be used in ST and IO as well as all of the transformers
Atomicity
Splitmix uses two Word64s for its state, so if we want atomicity the only right way is the MutVar, on the other hand if atomicity is not a requirement then we could use a small MutableByteArray for it's state therefore speeding up value generation in the stateful environment by avoiding one pointer indirection.
I personally propose having both of those implemented, since both of the implementations are pretty easy and straightforward. The latter faster-nonatmoic version is curently blocked by an actual switch to splitmix generator, however an even more general interface could be prepared for all pure nonatomic generators that have instance of Prim and/or Storable
Current interface has a way of generating values in IO with
randomIO. @Shimuuar pointed out that it could be useful to provide interface for such generator.There are a couple of choices we can make here. We could just as before wrap pure
StdGenin anIORef, but a better choice would be to usePrimMonadGenPrim
Creating a more general
GenPrim sby wrappingStdGenin aMutVarthat can be used inSTandIOas well as all of the transformersAtomicity
Splitmix uses two
Word64s for its state, so if we want atomicity the only right way is theMutVar, on the other hand if atomicity is not a requirement then we could use a smallMutableByteArrayfor it's state therefore speeding up value generation in the stateful environment by avoiding one pointer indirection.I personally propose having both of those implemented, since both of the implementations are pretty easy and straightforward. The latter faster-nonatmoic version is curently blocked by an actual switch to splitmix generator, however an even more general interface could be prepared for all pure nonatomic generators that have instance of
Primand/orStorable