FR
PréludeChargé par défaut — aucun import nécessaire.

Gen — pure generators with integrated (Hedgehog-style) shrinking

Synopsis
data Susp a = Susp (Lazy a)

A value kept waiting, for where Lazy cannot be written (in a list, a Maybe, a result): Susp e stores e uncomputed, and demand reads it, computing it once. (Lazy is written on a parameter or a field.)

demand : Susp a -> a
data ShrinkTree a = ShrinkNode a (Lazy (List (Susp (ShrinkTree a))))

A rose tree of shrinks: a value and a forest of (suspended) smaller candidates. The forest is lazy, so constructing a node costs nothing for its children — they are built only when shrinking actually explores them. A passing trial never forces it.

unfoldShrinkTree : (a -> List a) -> a -> ShrinkTree a

Build a tree by repeatedly applying a shrink function (children suspended).

bindShrinkTree : ShrinkTree a -> (a -> ShrinkTree b) -> ShrinkTree b

Monadic tree bind (the integrated-shrinking heart): shrink the outer value (re-running k on each outer shrink) and then the inner value.

data Gen a = MkGen (Int -> Int -> ShrinkTree a)

Gen a = Size -> Seed -> ShrinkTree a. Size and Seed are Int; the seed is oppi's splitmix (Random).

genValue : Int -> Int -> Gen a -> a

Generate just the value (drop the shrink tree).

splitSeed : Int -> (Int, Int)
mapGen : (a -> b) -> Gen a -> Gen b
pureGen : a -> Gen a
data Range = MkRange Int Int Int   -- origin lo hi

A Range fixes the bounds AND the origin — the value that shrinking moves toward. constant lo hi (see Data.Gen) is uniform with origin lo.

halves : Int -> List Int
towards : Int -> Int -> List Int

Integer shrinks of x toward origin: the origin first, then closing in on x by binary search. Works in both directions (so it terminates for x below origin too). towards 0 100 = [0, 50, 75, 88, 94, 97, 99]; towards 0 (negate 100) = [0, -50, -75, -88, -94, -97, -99].

genIntRange : Range -> Gen Int

The engine behind Data.Gen.int and the Arbitrary instances: a uniform integer in the range, shrinking toward its origin.

genBool : Gen Bool

A boolean; True shrinks to False (the minimal case).

shrinkCounterexample : (a -> Bool) -> ShrinkTree a -> a

Given a failing value's tree and the property, walk to a minimal failing value: greedily descend into the first failing child until none fails. This is what the runner does when a property is falsified. prop is the property HOLDING; the returned value is the smallest one where it FAILS.