numbering-0.2: Combinators for creating bijections from some type to the natural numbers.

Safe HaskellSafe-Infered

Data.Numbering

Contents

Synopsis

Documentation

data Numbering a Source

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.

Constructors

UnsafeMkNumbering 

Fields

toInt :: a -> Int
 
fromInt :: Int -> a
 
nuLength :: Int
 

Instances

Show a => Show (Numbering a) 

Construction

enumNu :: Enum a => a -> a -> Numbering aSource

enumNu a b creates a numbering of the elements [a .. b] (inclusively).

enumNu' :: Enum a => Int -> Int -> Numbering aSource

enumNu' i j creates a numbering of the elements [toEnum i .. toEnum j] (inclusively).

nuFromSet :: Map Int ignored -> Numbering IntSource

(Uses a Map because Data.Set doesn't expose the necessary index-based API)

nuFromDistinctVector :: (Ord a, Show a, Vector v a) => v a -> Numbering aSource

The distinctness precondition is checked (we have to create a map anyway).

nuFromDistinctVectorGSource

Arguments

:: (Show a, Vector v a) 
=> map

empty equivalent

-> ((a -> Int -> Int -> t) -> a -> Int -> map -> map)

insertWithKey equivalent

-> (a -> map -> Maybe Int)

lookup equivalent

-> v a 
-> Numbering a 

Allows customization of the map type used.

nuFromList :: (Ord a, Show a) => [a] -> Numbering aSource

Uniquifies the input first (resulting in an unspecified order).

nuFromUnboxList :: (Ord a, Show a, Unbox a) => [a] -> Numbering aSource

Uniquifies the input first (resulting in an unspecified order).

nuFromIntList :: [Int] -> Numbering IntSource

Uniquifies the input first (resulting in an unspecified order).

idNuSource

Arguments

:: Int

The nuLength

-> Numbering Int 

Identity numbering

Combination

sumNuSource

Arguments

:: (a1 -> a)

Left equivalent

-> (a2 -> a)

Right equivalent

-> ((a1 -> Int) -> (a2 -> Int) -> a -> Int)

either equivalent

-> Numbering a1 
-> Numbering a2 
-> Numbering a 

Creates a numbering for an Either-like type, given numberings for the summand types.

prodNuSource

Arguments

:: (a -> a2)

fst equivalent

-> (a -> a1)

snd equivalent

-> (a2 -> a1 -> a)

(,) equivalent

-> Numbering a2 
-> Numbering a1 
-> Numbering a 

Creates a numbering for an pair-like type, given numberings for the component types.

Destruction