-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Bijective mappings between values and possibly infinite prefixes of [0..]
--
-- Combinators and a class for creating bijective functions between
-- conceivably any data type definable and prefixes of the list of
-- natural numbers.
@package count
@version 0.0.1
module Data.Count.Counter
-- | 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.
data Counter a
UnsafeMkCounter :: Maybe Integer -> (a -> Integer) -> (Integer -> a) -> Counter a
cCount :: Counter a -> Maybe Integer
cToPos :: Counter a -> a -> Integer
cFromPos :: Counter a -> Integer -> a
-- | A counter for the single unit value.
unitCounter :: Counter ()
-- | A counter for an empty set of values, for any type.
voidCounter :: Counter a
-- | Counts through the natural numbers: [0..] maps simply to
-- [0..].
natCounter :: Counter Integer
-- | dropCounter n c drops the first n elements
-- from the given counter. cToPos (dropCounter n c)
-- 0 is equivalent to cToPos c 0.
dropCounter :: Integer -> Counter a -> Counter a
-- | Given two counters, a and b, creates a counter for
-- all Left-tagged a values and Right-tagged
-- b values.
sumCounter :: Counter a -> Counter b -> Counter (Either a b)
-- | Creates a counter for the Cartesian product of values in two given
-- counters.
prodCounter :: Counter a -> Counter b -> Counter (a, b)
-- | A counter for any Bounded Enum. [minBound
-- :: a ..] maps to [0..].
boundedEnumCounter :: (Bounded a, Enum a) => Counter a
isoCounter :: Counter a -> (b -> a) -> (a -> b) -> Counter b
maybeCounter :: Counter a -> Counter (Maybe a)
-- | 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.
listCounter :: Counter a -> Counter [a]
-- | Maps [0,1,-1,2,-2,..] to [0..]
integerCounter :: Counter Integer
-- | All values in the given counter, from the 0 correspondent
-- upwards.
allValuesFor :: Counter a -> [a]
module Data.Count
-- | Class and instances for producing Counters by type.
class Countable a
counter :: Countable a => Counter a
-- | Overloaded cToPos.
toPos :: Countable a => a -> Integer
-- | Overloaded cFromPos.
fromPos :: Countable a => Integer -> a
-- | Overloaded cCount. Doesn't attempt to reduce the dummy value
-- given.
count :: Countable a => a -> Maybe Integer
-- | Overloaded allValuesFor.
allValues :: Countable a => [a]
instance Countable a => Countable (Maybe a)
instance Countable a => Countable [a]
instance (Countable a, Countable b, Countable c, Countable d) => Countable (a, b, c, d)
instance (Countable a, Countable b, Countable c) => Countable (a, b, c)
instance (Countable a, Countable b) => Countable (a, b)
instance (Countable a, Countable b) => Countable (Either a b)
instance Countable ()
instance Countable Int64
instance Countable Int32
instance Countable Int16
instance Countable Int8
instance Countable Int
instance Countable Char
instance Countable Bool
instance Countable Integer