MIT licensed by Li-yao Xia
Maintained by [email protected]
This version can be pinned in stack with:generic-random-1.0.0.0@sha256:e05098e5a6535b3d1ab4777bdd6711c8f4639f205b1ef0b74b0f00b27b1b858a,1412
Depends on 2 packages(full list with versions):

Generic random generators Hackage Build Status

Derive simple random generators for QuickCheck using generics.

Example

    {-# LANGUAGE DeriveGeneric #-}

    import GHC.Generics (Generic)
    import Test.QuickCheck
    import Generic.Random

    data Tree a = Leaf | Node (Tree a) a (Tree a)
      deriving (Show, Generic)

    instance Arbitrary a => Arbitrary (Tree a) where
      arbitrary = genericArbitraryRec uniform `withBaseCase` return Leaf

    -- Equivalent to
    -- > arbitrary =
    -- >   sized $ \n ->
    -- >     if n == 0 then
    -- >       return Leaf
    -- >     else
    -- >       oneof
    -- >         [ return Leaf
    -- >         , resize (n `div` 3) $
    -- >             Node <$> arbitrary <*> arbitrary <*> arbitrary
    -- >         ]

    main = sample (arbitrary :: Gen (Tree ()))

Features

  • User-specified distribution of constructors.
  • A simple (optional) strategy to ensure termination for recursive types: using genericArbitrary', Test.QuickCheck.Gen’s size parameter decreases at every recursive call; when it reaches zero, sample directly from a trivially terminating generator.

Changes

https://github.com/Lysxia/generic-random/blob/master/changelog.md

1.0.0.0

  • Make the main module Generic.Random
  • Rework generic base case generation
    • You can explicitly provide a trivial generator (e.g., returning a nullary constructor) using withBaseCase
    • Generically derive BaseCaseSearch and let BaseCase find small values, no depth parameter must be specified anymore
  • Add genericArbitrarySingle, genericArbitraryRec, genericArbitraryU'
  • Deprecate weights
  • Fixed bug with genericArbitrary' not dividing the size parameter

0.5.0.0

  • Turn off dependency on boltzmann-samplers by default
  • Add genericArbitraryU, genericArbitraryU0 and genericArbitraryU1
  • Compatible with GHC 7.8.4 and GHC 7.10.3

0.4.1.0

  • Move Boltzmann sampler modules to another package: boltzmann-samplers

0.4.0.0

  • Check well-formedness of constructor distributions at compile time.
  • No longer support GHC 7.10.3 (the above feature relies on Generic information which does not exist before GHC 8)

0.3.0.0

  • Support GHC 7.10.3
  • Replace TypeApplications with ad-hoc data types in genericArbitraryFrequency'/genericArbitrary'