crowbar icon indicating copy to clipboard operation
crowbar copied to clipboard

Length of lists

Open lindig opened this issue 2 years ago • 1 comments

I have noticed that lists generated by list are short and I found no easy way to control their length. Should list not take a generator as argument for the length? This would make it easy to plug range or const for the length. Otherwise I would suggest to solve this problem in one of the examples.

lindig avatar Jul 11 '23 15:07 lindig

Looks like this is an inherent bug to the way size is dealt with throughout crowbar: looking at this line shows that the size begins hard coded at 100, making it impossible to actually dynamically generate longer lists.

i think if you use list right now, the maximum size you'll get is 6 (due to size scaling by -50% in the list gen). this alternative allows the maximum size to go up to 33 by making the size scaling -3 from the dynamic_bind generator instead:

let listn (g : 'a gen) : 'a list gen =
  fix (fun listn ->
      dynamic_bind (range 15) (fun n ->
          if n = 0 then const []
          else
            dynamic_bind g (fun x ->
                dynamic_bind listn (fun xs -> const (x :: xs)))))

nikhil-kamath avatar Dec 21 '23 07:12 nikhil-kamath