HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulegeneric-random-1.5.0.1Haskell2010

Generic.Random.DerivingVia

  • 10 types
  • 2 classes
newtypenewtype GenericArbitrary (weights :: k) a
#

Pick a constructor with a given distribution, and fill its fields with recursive calls to arbitrary.

Example
data X = ...
  deriving Arbitrary via (GenericArbitrary '[2, 3, 5] X)

Picks the first constructor with probability 2/10, the second with probability 3/10, the third with probability 5/10.

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitrary.

Instances3Eq, Show, Arbitrary
newtypenewtype GenericArbitraryU a
#

Pick every constructor with equal probability.

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitraryU.

Instances3Eq, Show, Arbitrary
newtypenewtype GenericArbitrarySingle a
#

arbitrary for types with one constructor. Equivalent to GenericArbitraryU, with a stricter type.

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitrarySingle.

Instances3Eq, Show, Arbitrary
newtypenewtype GenericArbitraryRec (weights :: k) a
#

Decrease size at every recursive call, but don't do anything different at size 0.

data X = ...
  deriving Arbitrary via (GenericArbitraryRec '[2, 3, 5] X)

N.B.: This replaces the generator for fields of type [t] with listOf' arbitrary instead of Test.QuickCheck.listOf arbitrary (i.e., arbitrary for lists).

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitraryRec.

Instances3Eq, Show, Arbitrary
newtypenewtype GenericArbitraryG (genList :: k) (weights :: k1) a
#

GenericArbitrary with explicit generators.

Example
data X = ...
  deriving Arbitrary via (GenericArbitraryG CustomGens '[2, 3, 5] X)

where, for example, custom generators to override String and Int fields might look as follows:

type CustomGens = CustomString :+ CustomInt
Note on multiple matches

Multiple generators may match a given field: the first will be chosen.

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitraryG.

Instances3Eq, Show, Arbitrary
newtypenewtype GenericArbitraryUG (genList :: k) a
#

GenericArbitraryU with explicit generators. See also GenericArbitraryG.

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitraryUG.

Instances3Eq, Show, Arbitrary
newtypenewtype GenericArbitrarySingleG (genList :: k) a
#

genericArbitrarySingle with explicit generators. See also GenericArbitraryG.

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitrarySingleG.

Instances3Eq, Show, Arbitrary
newtypenewtype GenericArbitraryRecG (genList :: k) (weights :: k1) a
#

genericArbitraryRec with explicit generators. See also genericArbitraryG.

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitraryRecG.

Instances3Eq, Show, Arbitrary
newtypenewtype GenericArbitraryWith (opts :: k) (weights :: k1) a
#

General generic generator with custom options.

This newtype does no shrinking. To add generic shrinking, use AndShrinking.

Uses genericArbitraryWith.

Instances3Eq, Show, Arbitrary
newtypenewtype AndShrinking (f :: k) a
#

Add generic shrinking to a newtype wrapper for Arbitrary, using genericShrink.

data X = ...
  deriving Arbitrary via (GenericArbitrary '[1,2,3] `AndShrinking' X)

Equivalent to:

instance Arbitrary X where
  arbitrary = genericArbitrary (1 % 2 % 3 % ())
  shrink = genericShrink

Constructors

Instances3Eq, Show, Arbitrary