adaptive-containers-0.3: Self optimizing container types




Self optimzing pair types.

This library statically adapts the polymorphic container representation of tuples to specific, more efficient representations, when instantiated with particular monomorphic types. It does this via an associated more efficient data type for each pair of elements you wish to store in your container.

That is, instead of representing '(Int,Char)' as:

           /   \
       I# 3#   C# x#

A self-optimizing pair will unpack the constructors, yielding this data representation:

       PairIntChar 3# x#

Saving two indirections. The resulting structure should be both more time and space efficient than the generic polymorphic container it is derived from. For example, adaptive pairs use 8 bytes to store an Int and Char pair, while a lazy pair uses 24 bytes.

 > Prelude Size> unsafeSizeof ((42, 'x') :: (Int,Char))
 > 24
 Prelude Size> unsafeSizeof (pair 42 'x' :: Pair Int Char)
 > 8

You can inspect the size and layout of your adaptive structures using two scripts, one for measuring the size of a closure, described in, and vacuum-cairo, for rendering the heap structure explicitly

Types that instantiate the Adapt class will self-adapt this way.

Self adaptive polymorphic containers are able to unpack their components, something not possible with, for example, strict polymorphic containers.



class AdaptPair a b whereSource

Representation-improving polymorphic tuples.

Associated Types

data Pair a b Source


fst :: Pair a b -> aSource

Extract the first component of a pair.

snd :: Pair a b -> bSource

Extract the second component of a pair.

curry :: (Pair a b -> c) -> a -> b -> cSource

curry converts an uncurried function to a curried function.


AdaptPair Bool Bool 
AdaptPair Char Char 
AdaptPair Char Double 
AdaptPair Char Float 
AdaptPair Char Int 
AdaptPair Char Int8 
AdaptPair Char Int16 
AdaptPair Char Int32 
AdaptPair Char Int64 
AdaptPair Char Integer 
AdaptPair Char Word 
AdaptPair Char Word8 
AdaptPair Char Word16 
AdaptPair Char Word32 
AdaptPair Char Word64 
AdaptPair Double Char 
AdaptPair Double Double 
AdaptPair Double Float 
AdaptPair Double Int 
AdaptPair Double Int8 
AdaptPair Double Int16 
AdaptPair Double Int32 
AdaptPair Double Int64 
AdaptPair Double Integer 
AdaptPair Double Word 
AdaptPair Double Word8 
AdaptPair Double Word16 
AdaptPair Double Word32 
AdaptPair Double Word64 
AdaptPair Float Char 
AdaptPair Float Double 
AdaptPair Float Float 
AdaptPair Float Int 
AdaptPair Float Int8 
AdaptPair Float Int16 
AdaptPair Float Int32 
AdaptPair Float Int64 
AdaptPair Float Integer 
AdaptPair Float Word 
AdaptPair Float Word8 
AdaptPair Float Word16 
AdaptPair Float Word32 
AdaptPair Float Word64 
AdaptPair Int Char 
AdaptPair Int Double 
AdaptPair Int Float 
AdaptPair Int Int 
AdaptPair Int Int8 
AdaptPair Int Int16 
AdaptPair Int Int32 
AdaptPair Int Int64 
AdaptPair Int Integer 
AdaptPair Int Word 
AdaptPair Int Word8 
AdaptPair Int Word16 
AdaptPair Int Word32 
AdaptPair Int Word64 
AdaptPair Int8 Char 
AdaptPair Int8 Double 
AdaptPair Int8 Float 
AdaptPair Int8 Int 
AdaptPair Int8 Int8 
AdaptPair Int8 Int16 
AdaptPair Int8 Int32 
AdaptPair Int8 Int64 
AdaptPair Int8 Integer 
AdaptPair Int8 Word 
AdaptPair Int8 Word8 
AdaptPair Int8 Word16 
AdaptPair Int8 Word32 
AdaptPair Int8 Word64 
AdaptPair Int16 Char 
AdaptPair Int16 Double 
AdaptPair Int16 Float 
AdaptPair Int16 Int 
AdaptPair Int16 Int8 
AdaptPair Int16 Int16 
AdaptPair Int16 Int32 
AdaptPair Int16 Int64 
AdaptPair Int16 Integer 
AdaptPair Int16 Word 
AdaptPair Int16 Word8 
AdaptPair Int16 Word16 
AdaptPair Int16 Word32 
AdaptPair Int16 Word64 
AdaptPair Int32 Char 
AdaptPair Int32 Double 
AdaptPair Int32 Float 
AdaptPair Int32 Int 
AdaptPair Int32 Int8 
AdaptPair Int32 Int16 
AdaptPair Int32 Int32 
AdaptPair Int32 Int64 
AdaptPair Int32 Integer 
AdaptPair Int32 Word 
AdaptPair Int32 Word8 
AdaptPair Int32 Word16 
AdaptPair Int32 Word32 
AdaptPair Int32 Word64 
AdaptPair Int64 Char 
AdaptPair Int64 Double 
AdaptPair Int64 Float 
AdaptPair Int64 Int 
AdaptPair Int64 Int8 
AdaptPair Int64 Int16 
AdaptPair Int64 Int32 
AdaptPair Int64 Int64 
AdaptPair Int64 Integer 
AdaptPair Int64 Word 
AdaptPair Int64 Word8 
AdaptPair Int64 Word16 
AdaptPair Int64 Word32 
AdaptPair Int64 Word64 
AdaptPair Integer Char 
AdaptPair Integer Double 
AdaptPair Integer Float 
AdaptPair Integer Int 
AdaptPair Integer Int8 
AdaptPair Integer Int16 
AdaptPair Integer Int32 
AdaptPair Integer Int64 
AdaptPair Integer Integer 
AdaptPair Integer Word 
AdaptPair Integer Word8 
AdaptPair Integer Word16 
AdaptPair Integer Word32 
AdaptPair Integer Word64 
AdaptPair Word Char 
AdaptPair Word Double 
AdaptPair Word Float 
AdaptPair Word Int 
AdaptPair Word Int8 
AdaptPair Word Int16 
AdaptPair Word Int32 
AdaptPair Word Int64 
AdaptPair Word Integer 
AdaptPair Word Word 
AdaptPair Word Word8 
AdaptPair Word Word16 
AdaptPair Word Word32 
AdaptPair Word Word64 
AdaptPair Word8 Char 
AdaptPair Word8 Double 
AdaptPair Word8 Float 
AdaptPair Word8 Int 
AdaptPair Word8 Int8 
AdaptPair Word8 Int16 
AdaptPair Word8 Int32 
AdaptPair Word8 Int64 
AdaptPair Word8 Integer 
AdaptPair Word8 Word 
AdaptPair Word8 Word8 
AdaptPair Word8 Word16 
AdaptPair Word8 Word32 
AdaptPair Word8 Word64 
AdaptPair Word16 Char 
AdaptPair Word16 Double 
AdaptPair Word16 Float 
AdaptPair Word16 Int 
AdaptPair Word16 Int8 
AdaptPair Word16 Int16 
AdaptPair Word16 Int32 
AdaptPair Word16 Int64 
AdaptPair Word16 Integer 
AdaptPair Word16 Word 
AdaptPair Word16 Word8 
AdaptPair Word16 Word16 
AdaptPair Word16 Word32 
AdaptPair Word16 Word64 
AdaptPair Word32 Char 
AdaptPair Word32 Double 
AdaptPair Word32 Float 
AdaptPair Word32 Int 
AdaptPair Word32 Int8 
AdaptPair Word32 Int16 
AdaptPair Word32 Int32 
AdaptPair Word32 Int64 
AdaptPair Word32 Integer 
AdaptPair Word32 Word 
AdaptPair Word32 Word8 
AdaptPair Word32 Word16 
AdaptPair Word32 Word32 
AdaptPair Word32 Word64 
AdaptPair Word64 Char 
AdaptPair Word64 Double 
AdaptPair Word64 Float 
AdaptPair Word64 Int 
AdaptPair Word64 Int8 
AdaptPair Word64 Int16 
AdaptPair Word64 Int32 
AdaptPair Word64 Int64 
AdaptPair Word64 Integer 
AdaptPair Word64 Word 
AdaptPair Word64 Word8 
AdaptPair Word64 Word16 
AdaptPair Word64 Word32 
AdaptPair Word64 Word64 
AdaptPair () () 

pair :: AdaptPair a b => a -> b -> Pair a bSource

Construct a new pair.

uncurry :: AdaptPair a b => (a -> b -> c) -> Pair a b -> cSource

uncurry converts a curried function to a function on pairs.

fromPair :: AdaptPair a b => Pair a b -> (a, b)Source

Convert an adaptive pair to a regular polymorphic tuple

toPair :: AdaptPair a b => (a, b) -> Pair a bSource

Convert a regular polymorphic tuple to an adaptive pair