generic-random: Generic random generators

[ generics, library, mit, testing ] [ Propose Tags ]

Please see the README below.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 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, 1.0.0.0, 1.1.0.0, 1.1.0.1, 1.1.0.2, 1.2.0.0, 1.3.0.0, 1.3.0.1, 1.4.0.0, 1.5.0.0, 1.5.0.1
Dependencies ad, base (>=4.8 && <4.9), containers, hashable, hmatrix, ieee754, MonadRandom, mtl, QuickCheck, transformers, unordered-containers, vector [details]
License MIT
Author Li-yao Xia
Maintainer lysxia@gmail.com
Revised Revision 2 made by lyxia at 2016-06-22T15:29:11Z
Category Generics, Testing
Home page http://github.com/lysxia/generic-random
Source repo head: git clone https://github.com/lysxia/generic-random
Uploaded by lyxia at 2016-05-17T15:49:10Z
Distributions Arch:1.5.0.1, Debian:1.3.0.1, LTSHaskell:1.5.0.1, NixOS:1.5.0.1, Stackage:1.5.0.1
Reverse Dependencies 8 direct, 2 indirect [details]
Downloads 27900 total (144 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for generic-random-0.1.0.0

[back to package description]

Generic random generators

Define sized random generators for almost any type.

    {-# LANGUAGE DeriveDataTypeable #-}
    import Data.Data
    import Test.QuickCheck
    import Data.Random.Generics

    data Term = Lambda Int Term | App Term Term | Var Int
      deriving (Show, Data)

    instance Arbitrary Term where
      arbitrary = sized $ generatorPWith [positiveInts]

    positiveInts :: Alias Gen
    positiveInts =
      alias $ \() -> fmap getPositive arbitrary :: Gen Int

    main = sample (arbitrary :: Gen Term)
  • Objects of the same size (number of constructors) occur with the same probability (see Duchon et al., references below).
  • Implements rejection sampling and pointing.
  • Works with QuickCheck and MonadRandom.
  • Can be extended or modified with user defined generators.

References