gencheck-0.1.1: A testing framework inspired by QuickCheck and SmallCheck

Safe HaskellSafe-Infered

Test.GenCheck.Generator.Enumeration

Description

Rational|, |Float| and |Double|. These `scalar' types require some additional structure. Most of the base type enumeration functions are in BaseTypeEnum.lhs.

All Haskell regular polynomial structure types can be enumerated by rank (size) using a mechanical algorithm based solely on the type constructor. These enumerations are constructed using the combinators eConst, eNode, eSum, eProd, etc. to mirror the type's constructor. Recursive structure enumerations should also be memoized to improve their performance since the count / selection of value at rank r is dependent on the count / selection of values at ranks $1$ through $(r-1)$. The eMemoize function provides the default memoization; additional memoization techniques are also provided in Memoize.lhs

Note: the Enumeration class differs from Haskell's Enum class in that the index of the enumerated value is unrecoverable, so the methods succ, pred, enumToInt, etc. are not required for the Enumeration instances.

Synopsis

Documentation

data Enumeration c a Source

Instances

type Counter = Rank -> CountSource

mkEnumeration| applies a default memoization strategy to both the counter and selector functions. |mkEnum| is just the raw constructor, and is used for enumerations that will be embedded in other enumerations to avoid redundant memoization. |mkEnum| should only be needed by experts and the Template Haskell code that assembles the enumeration combinators based on the type constructor.

An enumerated type may be defined to be an instance of the |Enumerated| class, which will automatically provide the default generators for that type as instances of StandardGens in the Generator module. The structures will have a Label (A, B, etc.) in each `hole' that distinguishes the sort of the element.

|get| retrieves a value from an enumeration given a rank and an index, or returns |Nothing| if the index is outside of the range of the enumeration. |getUnsafe| assumes the rank and index values are valid and in range, with unpredictable results if not.

type Selector c a = Rank -> Count -> c aSource

get :: Enumeration c a -> Rank -> Count -> Maybe (c a)Source

eProd :: (a x -> b x -> c x) -> Enumeration a x -> Enumeration b x -> Enumeration c xSource

eProd3 :: (a x -> b x -> c x -> d x) -> Enumeration a x -> Enumeration b x -> Enumeration c x -> Enumeration d xSource

eProd4 :: (a x -> b x -> c x -> d x -> e x) -> Enumeration a x -> Enumeration b x -> Enumeration c x -> Enumeration d x -> Enumeration e xSource

sConst, sNode :: (Num a, Num b, Eq a, Eq b) => t x -> a -> b -> t xSource

sProd :: (a x -> b x -> c x) -> Enumeration a x -> Enumeration b x -> Selector c xSource

sProd3 :: (a x -> b x -> c x -> d x) -> Enumeration a x -> Enumeration b x -> Enumeration c x -> Selector d xSource

sProd4 :: (a x -> b x -> c x -> d x -> e x) -> Enumeration a x -> Enumeration b x -> Enumeration c x -> Enumeration d x -> Selector e xSource

data Label Source

Constructors

A 
B 
C 
D 
E 
F 
G