| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell98 |
Data.Count.Counter
- data Counter a = UnsafeMkCounter {}
- unitCounter :: Counter ()
- voidCounter :: Counter a
- natCounter :: Counter Integer
- dropCounter :: Integer -> Counter a -> Counter a
- sumCounter :: Counter a -> Counter b -> Counter (Either a b)
- prodCounter :: Counter a -> Counter b -> Counter (a, b)
- boundedEnumCounter :: (Bounded a, Enum a) => Counter a
- isoCounter :: Counter a -> (b -> a) -> (a -> b) -> Counter b
- maybeCounter :: Counter a -> Counter (Maybe a)
- listCounter :: Counter a -> Counter [a]
- integerCounter :: Counter Integer
- allValuesFor :: Counter a -> [a]
Documentation
A maps bijectively between a subset of values of type Counter aa and some possibly empty or infinite prefix of [0..].
cCount is when the counter is finite and manages Just nn values, or when infinite.Nothing
cToPos converts a managed value to its natural number (starting from 0).
cFromPos converts a natural number to its managed value.
must be the identity function. This invariant is maintained using the combinators below.cToPos c . cFromPos c
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
drops the first dropCounter n cn elements from the given counter. is equivalent to cToPos (dropCounter n c) 0.cToPos c 0
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. [ maps to minBound :: a ..][0..].
isoCounter :: Counter a -> (b -> a) -> (a -> b) -> Counter b Source
maybeCounter :: Counter a -> Counter (Maybe a) 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.