-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Combinators for creating bijections from some type to the natural numbers. -- -- Combinators for creating bijections from a subset of an arbitrary type -- to a range of Ints, , e.g. for using libraries that require -- Int IDs. @package numbering @version 0.2 module Data.Numbering -- | Invariant: For all i in [ 0 .. nuLength - 1 -- ], toInt (fromInt i) == i. -- -- This implies that for all a of the form fromInt -- i (with i in [ 0 .. nuLength - 1 ]), -- fromInt (toInt a) = a. -- -- The behaviour of fromInt for out-of-bounds indices and that -- of toInt for elements not occuring in the numbering is -- undefined. data Numbering a UnsafeMkNumbering :: (a -> Int) -> (Int -> a) -> Int -> Numbering a toInt :: Numbering a -> a -> Int fromInt :: Numbering a -> Int -> a nuLength :: Numbering a -> Int -- | enumNu a b creates a numbering of the elements [a .. -- b] (inclusively). enumNu :: Enum a => a -> a -> Numbering a -- | enumNu' i j creates a numbering of the elements [toEnum i -- .. toEnum j] (inclusively). enumNu' :: Enum a => Int -> Int -> Numbering a -- | (Uses a Map because Data.Set doesn't expose the -- necessary index-based API) nuFromSet :: Map Int ignored -> Numbering Int -- | The distinctness precondition is checked (we have to create a map -- anyway). nuFromDistinctVector :: (Ord a, Show a, Vector v a) => v a -> Numbering a -- | Allows customization of the map type used. nuFromDistinctVectorG :: (Show a, Vector v a) => map -> ((a -> Int -> Int -> t) -> a -> Int -> map -> map) -> (a -> map -> Maybe Int) -> v a -> Numbering a -- | See nuFromDistinctVector. nuFromDistinctList :: (Ord a, Show a) => [a] -> Numbering a nuFromDistinctUnboxList :: (Ord a, Show a, Unbox a) => [a] -> Numbering a nuFromDistinctIntList :: [Int] -> Numbering Int -- | Uniquifies the input first (resulting in an unspecified order). nuFromList :: (Ord a, Show a) => [a] -> Numbering a -- | Uniquifies the input first (resulting in an unspecified order). nuFromUnboxList :: (Ord a, Show a, Unbox a) => [a] -> Numbering a -- | Uniquifies the input first (resulting in an unspecified order). nuFromIntList :: [Int] -> Numbering Int finiteTypeNu :: (Enum a, Bounded a) => Numbering a -- | Identity numbering idNu :: Int -> Numbering Int -- | Creates a numbering for an Either-like type, given numberings -- for the summand types. sumNu :: (a1 -> a) -> (a2 -> a) -> ((a1 -> Int) -> (a2 -> Int) -> a -> Int) -> Numbering a1 -> Numbering a2 -> Numbering a eitherNu :: Numbering a -> Numbering b -> Numbering (Either a b) -- | Creates a numbering for an pair-like type, given numberings for the -- component types. prodNu :: (a -> a2) -> (a -> a1) -> (a2 -> a1 -> a) -> Numbering a2 -> Numbering a1 -> Numbering a pairNu :: Numbering a -> Numbering b -> Numbering (a, b) nuIndices :: Numbering a -> [Int] nuElements :: Numbering a -> [a] data NumberingBrokenInvariantException a NumberingBrokenInvariantException :: Int -> a -> Int -> NumberingBrokenInvariantException a nbie_index :: NumberingBrokenInvariantException a -> Int nbie_fromIntOfIndex :: NumberingBrokenInvariantException a -> a nbie_toIntOfFromIntOfIndex :: NumberingBrokenInvariantException a -> Int checkNu :: Numbering a -> Either (NumberingBrokenInvariantException a) () instance Typeable1 NumberingBrokenInvariantException instance Show a => Show (NumberingBrokenInvariantException a) instance (Show a, Typeable a) => Exception (NumberingBrokenInvariantException a) instance Show a => Show (Numbering a)