The generic-random package

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

Warnings:

Please see the README.


[Skip to ReadMe]

Properties

Versions0.1.0.0, 0.1.1.0, 0.2.0.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
Change logNone available
Dependenciesad, base (>=4.8 && <5), containers, hashable, hmatrix, ieee754, MonadRandom, mtl, QuickCheck, transformers, unordered-containers, vector [details]
LicenseMIT
AuthorLi-yao Xia
Maintainerlysxia@gmail.com
CategoryGenerics, Testing
Home pagehttp://github.com/lysxia/generic-random
Source repositoryhead: git clone https://github.com/lysxia/generic-random
UploadedSun Aug 14 22:28:42 UTC 2016 by lyxia

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for generic-random-0.2.0.0

[back to package description]

Generic random generators Hackage Build Status

Generic.Random.Data

Define sized random generators for almost any type.

    {-# LANGUAGE DeriveDataTypeable #-}

    import Data.Data
    import Test.QuickCheck
    import Generic.Random.Data

    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)

Generic.Random.Generic

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

    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE DeriveGeneric #-}
    {-# LANGUAGE TypeApplications #-}

    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

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

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

Generic.Random.Boltzmann

An experimental interface to obtain Boltzmann samplers from an applicative specification of a combinatorial system.

No documentation (yet).

References

Papers about Boltzmann samplers, used in Generic.Random.Data: