Safe Haskell | Safe-Infered |
---|
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.
- data Enumeration c a
- class Functor c => Enumerated c where
- enumeration :: Enumeration c Label
- enumFromTo :: (Integer, Integer) -> Enumeration c Label
- type Counter = Rank -> Count
- type Selector c a = Rank -> Count -> c a
- mkEnum, mkEnumeration :: Counter -> Selector c a -> Enumeration c a
- counter :: Enumeration c a -> Counter
- selector :: Enumeration c a -> Selector c a
- get :: Enumeration c a -> Rank -> Count -> Maybe (c a)
- getUnsafe :: Enumeration c a -> Rank -> Count -> c a
- enumRange :: (Count, Count) -> Enumeration c a -> Enumeration c a
- eMemoize :: Enumeration c a -> Enumeration c a
- eConst, eNode :: c a -> Enumeration c a
- eSum :: Enumeration c a -> Enumeration c a -> Enumeration c a
- eSum3 :: Enumeration c a -> Enumeration c a -> Enumeration c a -> Enumeration c a
- eSum4 :: Enumeration c a -> Enumeration c a -> Enumeration c a -> Enumeration c a -> Enumeration c a
- eProd :: (a x -> b x -> c x) -> Enumeration a x -> Enumeration b x -> Enumeration c x
- eProd3 :: (a x -> b x -> c x -> d x) -> Enumeration a x -> Enumeration b x -> Enumeration c x -> Enumeration d x
- 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 x
- cConst, cNode :: Counter
- cSum, cProd :: Counter -> Counter -> Counter
- cSum3, cProd3 :: Counter -> Counter -> Counter -> Counter
- cSum4, cProd4 :: Counter -> Counter -> Counter -> Counter -> Counter
- sConst, sNode :: (Num a, Num b, Eq a, Eq b) => t x -> a -> b -> t x
- sSum :: Enumeration c a -> Enumeration c a -> Selector c a
- sSum3 :: Enumeration c a -> Enumeration c a -> Enumeration c a -> Selector c a
- sSum4 :: Enumeration c a -> Enumeration c a -> Enumeration c a -> Enumeration c a -> Selector c a
- sProd :: (a x -> b x -> c x) -> Enumeration a x -> Enumeration b x -> Selector c x
- sProd3 :: (a x -> b x -> c x -> d x) -> Enumeration a x -> Enumeration b x -> Enumeration c x -> Selector d x
- 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 x
- data Label
Documentation
data Enumeration c a Source
Functor c => Functor (Enumeration c) |
class Functor c => Enumerated c whereSource
enumeration :: Enumeration c LabelSource
enumFromTo :: (Integer, Integer) -> Enumeration c LabelSource
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.
mkEnum, mkEnumeration :: Counter -> Selector c a -> Enumeration c aSource
counter :: Enumeration c a -> CounterSource
selector :: Enumeration c a -> Selector c aSource
getUnsafe :: Enumeration c a -> Rank -> Count -> c aSource
enumRange :: (Count, Count) -> Enumeration c a -> Enumeration c aSource
eMemoize :: Enumeration c a -> Enumeration c aSource
eConst, eNode :: c a -> Enumeration c aSource
eSum :: Enumeration c a -> Enumeration c a -> Enumeration c aSource
eSum3 :: Enumeration c a -> Enumeration c a -> Enumeration c a -> Enumeration c aSource
eSum4 :: Enumeration c a -> Enumeration c a -> Enumeration c a -> Enumeration c a -> Enumeration c aSource
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
sSum :: Enumeration c a -> Enumeration c a -> Selector c aSource
sSum3 :: Enumeration c a -> Enumeration c a -> Enumeration c a -> Selector c aSource
sSum4 :: Enumeration c a -> Enumeration c a -> Enumeration c a -> Enumeration c a -> Selector c aSource
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