Skip to content

Implement MutGen.#17

Closed
lehins wants to merge 3 commits intointerface-to-performancefrom
mutgen
Closed

Implement MutGen.#17
lehins wants to merge 3 commits intointerface-to-performancefrom
mutgen

Conversation

@lehins
Copy link
Copy Markdown
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
Comment on lines +76 to +78
, runPrimGenST_
, runPrimGenIO
, runPrimGenIO_
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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