count-0.0.1: Bijective mappings between values and possibly infinite prefixes of [0..]

Data.Count.Counter

Synopsis

# Documentation

data Counter a Source

A `Counter a` maps bijectively between a subset of values of type `a` and some possibly empty or infinite prefix of `[0..]`.

`cCount` is `Just n` when the counter is finite and manages `n` values, or `Nothing` when infinite.

`cToPos` converts a managed value to its natural number (starting from 0).

`cFromPos` converts a natural number to its managed value.

`cToPos c . cFromPos c` must be the identity function. This invariant is maintained using the combinators below.

Constructors

 UnsafeMkCounter FieldscCount :: Maybe Integer cToPos :: a -> Integer cFromPos :: Integer -> a

A counter for the single unit value.

A counter for an empty set of values, for any type.

Counts through the natural numbers: `[0..]` maps simply to `[0..]`.

`dropCounter n c` drops the first `n` elements from the given counter. `cToPos (dropCounter n c) 0` is equivalent to `cToPos c 0`.

sumCounter :: Counter a -> Counter b -> Counter (Either a b)Source

Given two counters, `a` and `b`, creates a counter for all `Left`-tagged `a` values and `Right`-tagged `b` values.

prodCounter :: Counter a -> Counter b -> Counter (a, b)Source

Creates a counter for the Cartesian product of values in two given counters.

boundedEnumCounter :: (Bounded a, Enum a) => Counter aSource

A counter for any `Bounded` `Enum`. `[minBound :: a ..]` maps to `[0..]`.

isoCounter :: Counter a -> (b -> a) -> (a -> b) -> Counter bSource

listCounter :: Counter a -> Counter [a]Source

Counter for all lists of all values in given counter.

The count is 1 (the only value being the empty list) if the given counter is empty, infinite otherwise.

Maps [0,1,-1,2,-2,..] to [0..]

allValuesFor :: Counter a -> [a]Source

All values in the given counter, from the `0` correspondent upwards.