Skip to content

Document how to get an infinite int_range? #14

Description

@rauschma

Possibly worth mentioning: how do you produce an “infinite” range of integers?

This is what I did:

Gen.int_range 0 max_int

Activity

  1. c-cube commented on Jan 23, 2018

    @c-cube
    Owner

    Yes, it seems correct (almost infinite, though).
    If you want something truly infinite, try repeat or repeatedly:

    Gen.repeat 0 |> Gen.take 1_000_000 |> Gen.length;;

    or

    Gen.repeatedly (fun () -> 0) |> Gen.take 1_000_000 |> Gen.length;;

    If that's what you want, please submit a PR to add this to the .mli :)

  2. nilsbecker commented on May 29, 2019

    @nilsbecker

    wow, the second one sounds naively very inefficient? how about
    Gen.unfold (fun i -> Some (i, succ i)) 0?
    or maybe that was only for demonstation purposes. in any case by unfold also will wrap at max_int so it's really just a more convoluted version of the very first example.

  3. c-cube commented on May 29, 2019

    @c-cube
    Owner

    Why would the second one be inefficient? unfold can also do the job, yeah, I guess (or repeatedly with an internal ref that is incremented).

  4. nilsbecker commented on Jun 3, 2019

    @nilsbecker

    i probably misunderstood -- i thought you are using length to construct a generator of increasing integers like the OP asked. but Gen.length returns a simple integer so i guess it was only there to demonstrate the result.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions