Conversation
I don't quite understand this. It says that given |
@Shimuuar That is precisely why this suggestion cannot work. But considering that it has been suggested by at least 3 people that I know of, there is some confusion. Probably because people only think with transformers in their mind. Therefore I decided to solve the problem of confusion with an approach of renaming. Maybe |
b3ae4c7 to
14df799
Compare
|
Posting here a plan that I already shared privately for recovering freeze/thaw functionality: Just as before, but with a bit of renaming class StatefulGen (g s) m => SeededGen g s m | g -> s, m -> s where
type Seed g = (r :: *) | r -> s
saveGen :: g s -> m (Seed g)
restoreGen :: Seed g -> m (g s)
This would not only recover all of our functionality back, but also make it possible to create an instance for: https://www.stackage.org/haddock/lts-8.24/mersenne-random-1.0.0.1/System-Random-Mersenne.html#t:MTGen Other benefits of splitting this freezing/thawing functionality into a separate class is:
|
|
@lehins Now I'm even more confused. Why are saying that it's impossible? As I see both designs are pretty much equivalent. In one design dispatch is done over |
curiousleo
left a comment
There was a problem hiding this comment.
I think this is a great simplification, thanks for addressing the larger and smaller comments that we've received.
I've left a few minor comments.
|
Just to add to #144 (review) - my working assumption for the review was that we'd find some other way to add |
@Shimuuar I am not saying it is impossible, I am saying it is strictly worse! And they are far from equivalent. In By definition of |
|
@Shimuuar Given |
|
Now I understand. So main arguments against On other hand what are problems of @lehins By "equivalent" I meant that everything written in one style could be straightforwardly translated into other. But some things could be easier in one style of another. |
63df9d6 to
a48d55f
Compare
…unGenM and runGenM_
Co-authored-by: Leonhard Markert <curiousleo@users.noreply.github.com>
a48d55f to
85ec246
Compare
This is orthogonal to the current design because it can be easily solved by
It is best to use |
|
Posting it here new addition, which I think is really cool: Here is the new freeze/thaw interface I came up with. It is even better than before. @Shimuuar suggested at some point before possibility of flipping frozen and mutable around, but before it would have looked really ugly (every stateful gen would have had a signature class StatefulGen (MutableGen f m) m => FrozenGen f m where
type MutableGen f m = (g :: Type) | g -> f
freezeGen :: MutableGen f m -> m f
thawGen :: f -> m (MutableGen f m)mwc-random is a pleasure to look at instance PrimMonad m => FrozenGen MWC.Seed m where
type MutableGen MWC.Seed m = MWC.Gen (PrimState m)
thawGen = MWC.restore
freezeGen = MWC.saveand pure gen adapters are just as beautiful 🙂 instance (RandomGen g, MonadIO m) => FrozenGen (IOGen g) m where
type MutableGen (IOGen g) m = IOGenM g
freezeGen = fmap IOGen . liftIO . readIORef . unIOGenM
thawGen (IOGen g) = newIOGenM g
runGenM :: FrozenGen f m => f -> (MutableGen f m -> m a) -> m (a, f) |
Co-authored-by: Leonhard Markert <curiousleo@users.noreply.github.com>
Co-authored-by: Leonhard Markert <curiousleo@users.noreply.github.com>
Co-authored-by: Leonhard Markert <curiousleo@users.noreply.github.com>
That's why said that I'm unsure whether it'll be problem in practice. However one shouldn't underestimate ability of library user of using in weird and unanticipated ways. However only way to find out is to release library Also new version of |
Allow doctest-0.22
This PR covers some of them feedback we received from the community:
MonadRandom g s m- Removed the token and all functionality that relied on it:thawGenfreezeGen,withGenM...MonadRandom g m | m -> g- This is not a useful setup since it will require a generator to depend on a specific monad, which we are trying to avoid. Instead renamed the class toStatefulGen, to emphasize that it is the generator that is important, not the monad.random, setting it as a lower bound.Other adjustments:
-Weverythingto-Wallto avoid useless compilation warnings.