Skip to content

GenIO #15

@lehins

Description

@lehins

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions