liveBook · Manning

Generator size

As explained in Learn Haskell by Example

Generator size is a QuickCheck parameter that controls size-related characteristics of generated values.

Generator size is QuickCheck’s internal control for the scale of generated values. It defaults to 30, affects values such as Ints and lists, and can be changed with resize. section 9.4.1

Use generator size deliberately when building or inspecting generators:

  • Read the current size with getSize and use it to bound generated parameters. section 9.4.1
  • Let size propagate through nested generators unless you explicitly need resize. section 9.4.1
  • Use sample to observe behavior across sizes from 0 through 20, or resize for targeted inspection. section 9.4.1

Bounding a rotation amount

A generator can obtain size with getSize and choose a rotation amount between -size and size, keeping test data proportional to the configured scale.

How Learn Haskell by Example covers it

How deep it goes
Explains defaults, resizing, propagation, and internal use through getSize without detailing QuickCheck implementation internals.
Examples
Uses bounded alphabet-rotation data and integer samples generated with multiple resize values.
What you can do after
Apply it via QuickCheck by reading size with getSize, overriding it with resize, and sampling resulting values.
How it connects
Connects generator size with QuickCheck generators, Gen, getSize, resize, arbitrary, listOf, and sample.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.