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

StdGen: constructor accessible via Internal only #123

Merged
merged 1 commit into from
May 8, 2020

Conversation

curiousleo
Copy link
Collaborator

@curiousleo curiousleo commented May 7, 2020

Makes StdGen not an instance of Read.

Relates to haskell#59 (comment):

Removing the broken Read instance for StdGen is a reasonable solution and deleting the associated documentation would be a reasonable fix.

  • Benchmark to make sure this doesn't slow things down.

genWord32 = SM.nextWord32
genWord64 = SM.nextWord64
split = SM.splitSMGen
next = second StdGen . SM.nextInt . unStdGen
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effectively removes RandomGen SM.SMGen, which is not what we want.

We either need to add another instance or simply use GeneralizeNewtypeDeriving to derive RandomGen for StdGen

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lehins. I shouldn't have pushed this between meetings - silly mistakes.

I've updated this so we keep RandomGen SM.SMGen and use GeneralisedNewtypeDeriving for RandomGen StdGen.

@lehins
Copy link
Collaborator

lehins commented May 7, 2020

This is not a problem for us anymore: haskell#59 (comment) , because SMGen defines a sensible Read instance.

λ> read "abcdef" :: StdGen
*** Exception: Prelude.read: no parse
λ> read "SMGen 1 3" :: StdGen
SMGen 1 3

That being said, I personally think Read is wart in Haskell, so getting rid of that instance for StdGen is fine with me. newtype wrapper is not a bad idea either, now that we have an internal module that can expose the constructor for those who need it

@curiousleo
Copy link
Collaborator Author

That being said, I personally think Read is wart in Haskell, so getting rid of that instance for StdGen is fine with me.

👍

newtype wrapper is not a bad idea either, now that we have an internal module that can expose the constructor for those who need it

That was one of my initial motivations for introducing Internal.

@curiousleo curiousleo marked this pull request as ready for review May 8, 2020 11:41
@curiousleo curiousleo requested a review from idontgetoutmuch May 8, 2020 11:41
Fixes haskell#59 by making 'StdGen' not
an instance of 'Read'.
@curiousleo curiousleo merged commit 9ee79a7 into interface-to-performance May 8, 2020
@lehins
Copy link
Collaborator

lehins commented May 8, 2020

@curiousleo I was a bit too slow to comment. We also could benefit from Eq instance. See haskell#45 for such request. As well as NFData, which can be derived.

@lehins
Copy link
Collaborator

lehins commented May 8, 2020

Ended up adding Eq and NFData in #125

@idontgetoutmuch idontgetoutmuch deleted the stdgen-newtype branch May 8, 2020 14:45
@curiousleo
Copy link
Collaborator Author

@curiousleo I was a bit too slow to comment. We also could benefit from Eq instance. See haskell#45 for such request. As well as NFData, which can be derived.

Sorry. I think I was a bit too quick to merge!

curiousleo added a commit that referenced this pull request May 13, 2020
Fixes haskell#59 by making 'StdGen' not
an instance of 'Read'.
curiousleo added a commit that referenced this pull request May 13, 2020
Fixes haskell#59 by making 'StdGen' not
an instance of 'Read'.
lehins pushed a commit that referenced this pull request May 18, 2020
Fixes haskell#59 by making 'StdGen' not
an instance of 'Read'.
curiousleo added a commit that referenced this pull request May 19, 2020
Fixes haskell#59 by making 'StdGen' not
an instance of 'Read'.
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.

3 participants