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

Safe HaskellSafe-Inferred
LanguageHaskell98

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 

Fields

cCount :: Maybe Integer
 
cToPos :: a -> Integer
 
cFromPos :: Integer -> a
 

unitCounter :: Counter () Source

A counter for the single unit value.

voidCounter :: Counter a Source

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

natCounter :: Counter Integer Source

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

dropCounter :: Integer -> Counter a -> Counter a Source

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 a Source

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

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

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.

integerCounter :: Counter Integer Source

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

allValuesFor :: Counter a -> [a] Source

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