-
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
Addition of state token to MonadRandom #79
Conversation
|
For comparison, without to this PR, MWC can be made an instance of instance (s ~ PrimState m, PrimMonad m) => MonadRandom (MWC.Gen s) m where
newtype Frozen (MWC.Gen s) = FrozenGen MWC.Seed
thawGen (FrozenGen s) = MWC.restore s The benefit of this change is not clear to me. Would users need to enable |
Conflict resolved here: https://github.com/idontgetoutmuch/random/compare/interface-to-performance...idontgetoutmuch:monad-random-state-token-rebased?expand=1 Feel free to force-push b83bebd to Edit: done. |
e26eb04
to
b83bebd
Compare
No, they won't have to. Only when you create an instance you might need to use that extension.
Benefit is that
Here is an example type signature restricted to thawGen :: Frozen (Gen s) -> ST s (Gen s) Which with this PR becomes: thawGen :: Frozen Gen -> ST s (Gen s) Because |
Oh, by the way, totally forgot to mention that this futzing around in attempt to solve this issue resulted in a discover of a bug in ghc: https://gitlab.haskell.org/ghc/ghc/issues/18021 |
And to think that I dropped three parameter MonadRandom as obviously ugly! class Monad m => MonadRandom (g :: * -> *) s m | m -> s where
|
@Shimuuar Here is a PR that creates a few instances for this approach, so funcdeps seem to work out fine, in fact without it is a bit problematic for instances that rely on I don't see how that can happen:
It is only a problem if generator and monad are both the same in two different instances Good catch, I experimenting with poly kinded alternatives, I'll remove the annotation.
Ugliness is certainly a matter of perspective :)
What do you think? Which one of these type signatures is more appealing: uniformInt :: MonadRandom g s m => g s -> m Int or this uniformInt :: MonadRandom g m => g (StateToken g m) -> m Int So, overall, @Shimuuar do you think is a viable solution to the problem from #71 and overall a decent design? |
To elaborate more I meant that
Strongly, yes! |
Addition of state token to MonadRandom
@Shimuuar I think I found a simple and elegant solution to our Frozen conundrum. Very similar to what you did in #71 except using fun deps.
Instance form MWC becomes really nice:
This approach adds very clutter around. It makes slightly uglier for
PureGen
and other instances that don't care about a state token (eg. IORef), but that's the price we'll have to pay for generality.Let me know what you think.