MIT licensed by Li-yao Xia
Maintained by [email protected]
This version can be pinned in stack with:generic-random-0.4.1.0@sha256:8d04188fe17e41eb33ae5ba9310dfa4ddef2d267893da95a2638493f55c3fbe4,1179

Module documentation for 0.4.1.0

Generic random generators Hackage Build Status

Say goodbye to Constructor <$> arbitrary <*> arbitrary <*> arbitrary-boilerplate.

    {-# LANGUAGE DeriveGeneric #-}

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

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

    instance Arbitrary a => Arbitrary (Tree a) where
      arbitrary = genericArbitrary' Z uniform

    -- Equivalent to
    -- > arbitrary =
    -- >   sized $ \n ->
    -- >     if n == 0 then
    -- >       return Leaf
    -- >     else
    -- >       oneof
    -- >         [ return Leaf
    -- >         , Node <$> arbitrary <*> arbitrary <*> arbitrary
    -- >         ]

    main = sample (arbitrary :: Gen (Tree ()))
  • User-specified distribution of constructors, with a compile-time check that weights have been specified for all constructors.
  • A simple (optional) strategy to ensure termination: Test.QuickCheck.Gen’s size parameter decreases at every recursive genericArbitrary' call; when it reaches zero, sample directly from a finite set of finite values.

Changes

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’