liveBook · Manning

Resize

As explained in Learn Haskell by Example

resize is a QuickCheck combinator that changes the size parameter used by a generator.

resize is a QuickCheck combinator that changes the internal size used by a generator. Size controls generated values: Int values use it as an absolute bound, while listOf uses it to influence list length. The default size is 30. section 9.4.1

Use resize when you need to control generated data externally:

  • Increase the size to explore larger values or structures. section 9.4.1
  • Keep custom generators size-aware by reading getSize when constructing values. section 9.4.1
  • Let size propagate through nested generators unless deliberate resizing is required. section 9.4.1

Sampling larger integers

sample $ generate (resize 100 $ arbitrary :: Gen Int) produces integers within a much larger range than the default-sized generator; resize 10000 explores still larger values.

How Learn Haskell by Example covers it

How deep it goes
Defines the size parameter, default size, effects on generators, and propagation through nested generators.
Examples
Samples arbitrary Int values using the default size, resize 100, and resize 10000.
What it assumes
Assumes QuickCheck generators and teaches how their internal size influences generated values.
What you can do after
Apply it via QuickCheck to explore larger generated values and manage generator performance.
How it connects
Connects QuickCheck generators with Gen, arbitrary, getSize, 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.