Skip to content

read :: StdGen fails for strings longer than 6 #59

Description

@joeyh
ghci> read "abcdef" :: StdGen
36217 1
ghci> read "abcdefg" :: StdGen
** * Exception: Prelude.read: no parse

This is contrary to the documentation: "It guarantees to succeed on any string. "

random-1.1
ghc-8.6.5

Activity

  1. cartazio commented on Mar 10, 2020

    @cartazio
    Contributor
  2. cartazio commented on Mar 10, 2020

    @cartazio
    Contributor
  3. andrewthad commented on Mar 10, 2020

    @andrewthad

    It's a guarantee provided in the docs for random:

    In addition, 'reads' may be used to map an arbitrary string (not necessarily one produced by 'show') onto a value of type 'StdGen'. In general, the 'Read' instance of 'StdGen' has the following properties:

    • It guarantees to succeed on any string.
    • It guarantees to consume only a finite portion of the string.
    • Different argument strings are likely to result in different results.

    This is a weird thing to do with reads. Removing the broken Read instance for StdGen is a reasonable solution and deleting the associated documentation would be a reasonable fix.

  4. cartazio commented on Mar 10, 2020

    @cartazio
    Contributor
  5. idontgetoutmuch commented on Mar 11, 2020

    @idontgetoutmuch
    Member

    I'd recommend using splitmix as

    • It's the fastest
    • Passes e.g. BigCrush so plenty good enough for non-cryptographic applications
    • Has a good split function
    • Is used by QuickCheck

    See here for the details on speed and quality (which you can run yourself ):

  6. cartazio commented on Mar 11, 2020

    @cartazio
    Contributor
  7. curiousleo commented on Mar 11, 2020

    @curiousleo
    Contributor

    Pcg does better on big crush last I checked than splitmix.

    SplitMix passes all BigCrush tests: https://github.com/tweag/random-quality/blob/master/results/splitmix-word32-testu01-bigcrush#L3775-L3782

  8. 1 remaining item

  9. lehins commented on Jun 23, 2020

    @lehins
    Contributor

    Fixed. Read instance was removed in random-1.2. See #62

  10. added this to the 1.2.0 milestone on Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions