Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Implement MutGen. #17

wants to merge 3 commits into from

Conversation

lehins
Copy link
Collaborator

@lehins lehins commented Mar 2, 2020

This PR implements an effectful generator backed by a MutableByteArray as described in #15

@lehins lehins mentioned this pull request Mar 2, 2020
System/Random.hs Outdated
Comment on lines 76 to 78
, runPrimGenST_
, runPrimGenIO
, runPrimGenIO_
Copy link
Collaborator

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}_)

Copy link
Collaborator Author

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.

@curiousleo curiousleo changed the base branch from primgen to interface-to-performance March 13, 2020 15:27
@lehins lehins closed this Mar 13, 2020
@lehins
Copy link
Collaborator Author

lehins commented Mar 13, 2020

Closed in favor of #33

@curiousleo curiousleo deleted the mutgen branch March 17, 2020 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants