-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement MutGen. #17
Conversation
System/Random.hs
Outdated
, runPrimGenST_ | ||
, runPrimGenIO | ||
, runPrimGenIO_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that discarding generators is common enough to warrant the extra functions, or were these added mostly for benchmarking? (Same for runMutGen{ST,IO}_
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, in fact I believe it will be more common than runMutGen{IO,ST}
.
There is a very good chance you only need a single generator for your whole application that you will just thread through in the environment either directly or with Reader
pattern
Therefore I expect something like this will be a very common pattern:
main = do
... parse cli, read config from file, initialize your app environment, etc.
g <- initSystemGen -- or grab the seed from config/cli
runPrimGenIO_ g $ \ primGen ->
...
let env = AppEnv primGen ...
runApp env
If you need more than a single generator you can just use splitPrimGen
. Point is, that at some point any application will be done with needing random numbers, thus there will no longer be a need for the generator and since a user already bought into the effectful RNG, it is unlikely that he'll need to recover the pure version after the computation is complete. At the same time we don't need to make it hard to get the pure generator back either, therefore I think runMutGen{IO,ST}
will be useful as well.
Closed in favor of #33 |
This PR implements an effectful generator backed by a
MutableByteArray
as described in #15