Safe Haskell | Safe-Infered |
---|

This module contains a (hopefully) manageable subset of the functionality of Feat. The rest resides only in the Test.Feat.* modules.

- data Enumerate a = Enumerate {}
- class Typeable a => Enumerable a where
- nullary :: a -> Constructor a
- unary :: Enumerable a => (a -> b) -> Constructor b
- funcurry :: (a -> b -> c) -> FreePair a b -> c
- consts :: [Constructor a] -> Enumerate a
- deriveEnumerable :: Name -> Q [Dec]
- newtype FreePair a b = Free {
- free :: (a, b)

- optimised :: Enumerable a => Enumerate a
- index :: Enumerate a -> Integer -> a
- values :: Enumerable a => [(Integer, [a])]
- bounded :: Enumerable a => Integer -> [(Integer, [a])]
- uniform :: Enumerable a => Int -> Gen a
- ioFeat :: [(Integer, [a])] -> (a -> IO ()) -> IO ()
- ioAll :: Enumerable a => (a -> IO ()) -> IO ()
- ioBounded :: Enumerable a => Integer -> (a -> IO ()) -> IO ()

# Documentation

A functional enumeration of type `t`

is a partition of
`t`

into finite numbered sets called Parts. The number that
identifies each part is called the cost of the values in
that part.

# The type class

class Typeable a => Enumerable a whereSource

A class of functionally enumerable types

enumerate :: Enumerate aSource

This is the interface for defining an instance. Memoisation needs to
be ensured e.g. using `mempay`

but sharing is handled automatically by
the default implementation of `shared`

.

Version of enumerate that ensures it is shared between all accessing functions. Should always be used when combining enumerations. Should typically be left to default behaviour.

nullary :: a -> Constructor aSource

For nullary constructors such as `True`

and `[]`

.

unary :: Enumerable a => (a -> b) -> Constructor bSource

For any non-nullary constructor. Apply `funcurry`

until the type of
the result is unary (i.e. n-1 times where n is the number of fields
of the constructor).

funcurry :: (a -> b -> c) -> FreePair a b -> cSource

Uncurry a function (typically a constructor) to a function on free pairs.

consts :: [Constructor a] -> Enumerate aSource

Produces the enumeration of a type given the enumerators for each of its
constructors. The result of `unary`

should typically not be used
directly in an instance even if it only has one constructor. So you
should apply consts even in that case.

deriveEnumerable :: Name -> Q [Dec]Source

Derive an instance of Enumberable with Template Haskell.

A free pair constructor. The cost of constructing a free pair is equal to the sum of the costs of its components.

Typeable2 FreePair | |

(Show a, Show b) => Show (FreePair a b) | |

(Enumerable a, Enumerable b) => Enumerable (FreePair a b) |

# Accessing data

optimised :: Enumerable a => Enumerate aSource

An optimised version of enumerate. Used by all
library functions that access enumerated values (but not
by combining functions). Library functions should ensure that
`optimised`

is not reevaluated.

index :: Enumerate a -> Integer -> aSource

Mainly as a proof of concept we can use the isomorphism between
natural numbers and `(Part,Index)`

pairs to index into a type.
May not terminate for finite types.
Might be slow the first time it is used with a specific enumeration
because cardinalities need to be calculated.
The computational complexity (after cardinalities are computed) is a polynomial
in the size of the resulting value.

values :: Enumerable a => [(Integer, [a])]Source

All values of the enumeration by increasing cost (which is the number of constructors for most types). Also contains the cardinality of each list.

bounded :: Enumerable a => Integer -> [(Integer, [a])]Source

A version of vales that has a limited number of values in each inner list. If the list corresponds to a Part which is larger than the bound it evenly intersperses the values across the enumeration of the Part.

uniform :: Enumerable a => Int -> Gen aSource

Compatibility with QuickCheck. Distribution is uniform generator over
values bounded by the given size. Typical use: `sized uniform`

.

ioFeat :: [(Integer, [a])] -> (a -> IO ()) -> IO ()Source

A rather simple but general property testing driver. The property is an (funcurried) IO function that both tests and reports the error. The driver goes on forever or until the list is exhausted, reporting the coverage and the number of tests before each new part.