The generic-random package

[Tags:library, mit]

Please see the README. Note: this package no longer exports Boltzmann samplers by default although they appear below. (Generic.Random.Data, Generic.Random.Boltzmann)


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.1.0, 0.2.0.0, 0.3.0.0, 0.4.0.0, 0.4.1.0, 0.5.0.0
Change log CHANGELOG.md
Dependencies base (>=4.7 && <4.10), boltzmann-samplers (<=0.2), QuickCheck [details]
License MIT
Author Li-yao Xia
Maintainer lysxia@gmail.com
Category Generics, Testing
Home page http://github.com/lysxia/generic-random
Source repository head: git clone https://github.com/lysxia/generic-random
Uploaded Mon Apr 10 15:27:49 UTC 2017 by lyxia
Updated Mon Apr 10 15:41:04 UTC 2017 by lyxia to revision 1
Distributions LTSHaskell:0.4.1.0, NixOS:0.5.0.0, Stackage:0.5.0.0, Tumbleweed:0.4.1.0
Downloads 386 total (33 in the last 30 days)
Votes
2 []
Status Docs available [build log]
Last success reported on 2017-04-10 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Flags

NameDescriptionDefaultType
boltzmannDependency on boltzmann-samplers for backwards compatibility.DisabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for generic-random

Readme for generic-random-0.5.0.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.