liveBook · Manning

Sample

As explained in Learn Haskell by Example

sample is a QuickCheck operation that displays generated values across a range of generator sizes.

sample is a QuickCheck operation for inspecting a generator’s output across a progression of sizes. Rather than showing values from one fixed size, it runs sizes from 0 through 20, making changes in generated shape or magnitude visible quickly. section 9.4.1

Use it while designing a generator, especially one whose output should scale with size. Generators can read the current size with getSize; that size propagates into nested generators, while resize deliberately overrides it when a different bound is needed. section 9.4.1

Inspecting a size-sensitive generator

For a generator that chooses an alphabet, an offset, and a character from that alphabet, use sample to check how its values evolve as size rises. Keep the generator size-aware: derive the offset range from getSize, restrict alphabets to nonempty values, and select the character from the chosen alphabet. section 9.4.1

This inspection is complementary to property testing. After checking that generated cases look plausible, pass the generator to forAll so a property is tested against explicitly controlled test data. section 9.4.1

How Learn Haskell by Example covers it

How deep it goes
Explains the 0-to-20 size progression and relates it to getSize, resize, and generator composition.
Examples
Uses an alphabet-rotation data generator with nonempty alphabets, size-bounded offsets, and selected characters.
What it assumes
Introduces size-aware generator construction through getSize and shows resizing only when an explicit override is needed.
What you can do after
Evaluate/understand whether a generator’s values change plausibly as its QuickCheck size varies.
How it connects
Connects sample with Gen, getSize, resize, arbitrary, generate, and forAll.

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.