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

Deprecate RandomGenM in favor of a more powerful FrozenGen #149

Merged
merged 4 commits into from
Nov 24, 2023

Conversation

lehins
Copy link
Contributor

@lehins lehins commented Oct 28, 2023

  • Addition of modifyGen totally removes the need for RandomGenM, because every frozen generator that is a netwtype wrapper around RandomGen also derives an instance for RandomGen
  • Add splitMutableGen and splitGen
  • Add ThawedGen and move thawGen into that type class to combat current unlawful FrozenGen instance for StateGen

@lehins lehins force-pushed the lehins/extend-frozen-gen branch 5 times, most recently from 618b5e4 to 2fba77c Compare October 29, 2023 20:19
@lehins lehins mentioned this pull request Oct 30, 2023
@Shimuuar
Copy link
Contributor

That's great! It provides direct correspondence between RandomGen based API and StatefulGen one. Just a few thoughtsfrom me:

  1. modifyM clashes with one from transformers state monad. modifyGen?
  2. This addition mean that one could implement thawGenInplace :: MutableGen f m -> f -> m () which replaces existing mutable generator.

@lehins
Copy link
Contributor Author

lehins commented Oct 30, 2023

  1. modifyM clashes with one from transformers state monad. modifyGen?

modifyGen sounds good to me.

  1. This addition mean that one could implement thawGenInplace :: MutableGen f m -> f -> m () which replaces existing mutable generator.

Yes, that seems like a good feature to me.

@lehins lehins force-pushed the lehins/extend-frozen-gen branch from 2fba77c to 66f0f10 Compare November 12, 2023 12:06
@lehins lehins force-pushed the lehins/extend-frozen-gen branch 4 times, most recently from 14ce716 to c7eb9bd Compare November 24, 2023 15:03
* Addition of `modifyGen` totally removes the need for `RandomGenM`, because
every frozen generator that is a wrapper around `RandomGen` also derives
an instance for `RandomGen`

* Add `splitMutableM` and `splitFrozenM`

* Avoid redundant freeze in `withMutableGen_`
* Also add some laws for `FrozenGen` and `ThawedGen`

This split of `FrozenGen` type class into two is needed because some
mutable generators can't be cloned, becase the mutable state is
stored in the monad they are running in, rather than in the mutable
generator itself.
@lehins lehins force-pushed the lehins/extend-frozen-gen branch from c7eb9bd to bc58313 Compare November 24, 2023 15:27
@lehins
Copy link
Contributor Author

lehins commented Nov 24, 2023

This addition mean that one could implement thawGenInplace :: MutableGen f m -> f -> m () which replaces existing mutable generator.

@Shimuuar I've added overwriteGen :: MutableGen f m -> f -> m () to make this feature explicit and allow for more efficient implementation, like in this PR: haskell/mwc-random#89 with copy

@lehins lehins merged commit 9f92421 into master Nov 24, 2023
48 checks passed
lehins added a commit that referenced this pull request Nov 26, 2023
Also fixup example with `FrozenGen` instance in haddock
@lehins lehins deleted the lehins/extend-frozen-gen branch November 26, 2023 18:26
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