Safe Haskell | None |
---|---|
Language | Haskell2010 |
Internal API for TypeRepMap
and operations on it. The functions here do
not have any stability guarantees and can change between minor versions.
If you need to use this module for purposes other than tests, create an issue.
Synopsis
- data TypeRepMap (f :: k -> Type) = TypeRepMap {
- fingerprintAs :: !(PrimArray Word64)
- fingerprintBs :: !(PrimArray Word64)
- anys :: !(Array Any)
- toFingerprints :: TypeRepMap f -> [Fingerprint]
- empty :: TypeRepMap f
- one :: forall a f. Typeable a => f a -> TypeRepMap f
- insert :: forall a f. Typeable a => f a -> TypeRepMap f -> TypeRepMap f
- type KindOf (a :: k) = k
- delete :: forall a (f :: KindOf a -> Type). Typeable a => TypeRepMap f -> TypeRepMap f
- hoist :: (forall x. f x -> g x) -> TypeRepMap f -> TypeRepMap g
- unionWith :: (forall x. f x -> f x -> f x) -> TypeRepMap f -> TypeRepMap f -> TypeRepMap f
- union :: TypeRepMap f -> TypeRepMap f -> TypeRepMap f
- member :: forall a (f :: KindOf a -> Type). Typeable a => TypeRepMap f -> Bool
- lookup :: forall a f. Typeable a => TypeRepMap f -> Maybe (f a)
- size :: TypeRepMap f -> Int
- cachedBinarySearch :: Fingerprint -> PrimArray Word64 -> PrimArray Word64 -> Maybe Int
- toAny :: f a -> Any
- fromAny :: Any -> f a
- typeFp :: forall a. Typeable a => Fingerprint
- toPairList :: TypeRepMap f -> [(Fingerprint, Any)]
- deleteByFst :: Eq a => a -> [(a, b)] -> [(a, b)]
- nubByFst :: Eq a => [(a, b)] -> [(a, b)]
- data TF f where
- fromList :: forall f. [TF f] -> TypeRepMap f
- fromF :: Typeable a => f a -> Proxy a
- calcFp :: Typeable a => f a -> Fingerprint
- fromListPairs :: [(Fingerprint, Any)] -> TypeRepMap f
- fromSortedList :: forall a. [a] -> [a]
Documentation
data TypeRepMap (f :: k -> Type) Source #
TypeRepMap
is a heterogeneous data structure similar in its essence to
Map
with types as keys, where each value has the type of its key. In
addition to that, each value is wrapped in an interpretation f
.
Here is an example of using Maybe
as an interpretation, with a
comparison to Map
:
Map
String
(Maybe
String
)TypeRepMap
Maybe
--------------------------- --------------------- "Int" -> Just "5"Int
-> Just 5 "Bool" -> Just "True"Bool
-> JustTrue
"Char" -> NothingChar
-> Nothing
The runtime representation of TypeRepMap
is an array, not a tree. This makes
lookup
significantly more efficient.
TypeRepMap | an unsafe constructor for |
|
Instances
Show (TypeRepMap f) Source # | Shows only |
Defined in Data.TypeRepMap.Internal showsPrec :: Int -> TypeRepMap f -> ShowS # show :: TypeRepMap f -> String # showList :: [TypeRepMap f] -> ShowS # | |
Semigroup (TypeRepMap f) Source # | Uses |
Defined in Data.TypeRepMap.Internal (<>) :: TypeRepMap f -> TypeRepMap f -> TypeRepMap f # sconcat :: NonEmpty (TypeRepMap f) -> TypeRepMap f # stimes :: Integral b => b -> TypeRepMap f -> TypeRepMap f # | |
Monoid (TypeRepMap f) Source # | |
Defined in Data.TypeRepMap.Internal mempty :: TypeRepMap f # mappend :: TypeRepMap f -> TypeRepMap f -> TypeRepMap f # mconcat :: [TypeRepMap f] -> TypeRepMap f # |
toFingerprints :: TypeRepMap f -> [Fingerprint] Source #
Returns the list of Fingerprint
s from TypeRepMap
.
empty :: TypeRepMap f Source #
one :: forall a f. Typeable a => f a -> TypeRepMap f Source #
insert :: forall a f. Typeable a => f a -> TypeRepMap f -> TypeRepMap f Source #
Insert a value into a TypeRepMap
.
size (insert v tm) >= size tm
member @a (insert (x :: f a) tm) == True
delete :: forall a (f :: KindOf a -> Type). Typeable a => TypeRepMap f -> TypeRepMap f Source #
Delete a value from a TypeRepMap
.
size (delete @a tm) <= size tm
member @a (delete @a tm) == False
>>>
tm = delete @Bool $ insert (Just True) $ one (Just 'a')
>>>
size tm
1>>>
member @Bool tm
False>>>
member @Char tm
True
hoist :: (forall x. f x -> g x) -> TypeRepMap f -> TypeRepMap g Source #
Map over the elements of a TypeRepMap
.
>>>
tm = insert (Identity True) $ one (Identity 'a')
>>>
lookup @Bool tm
Just (Identity True)>>>
lookup @Char tm
Just (Identity 'a')>>>
tm2 = hoist ((:[]) . runIdentity) tm
>>>
lookup @Bool tm2
Just [True]>>>
lookup @Char tm2
Just "a"
unionWith :: (forall x. f x -> f x -> f x) -> TypeRepMap f -> TypeRepMap f -> TypeRepMap f Source #
The union of two TypeRepMap
s using a combining function.
union :: TypeRepMap f -> TypeRepMap f -> TypeRepMap f Source #
The (left-biased) union of two TypeRepMap
s. It prefers the first map when
duplicate keys are encountered, i.e.
.union
== unionWith
const
member :: forall a (f :: KindOf a -> Type). Typeable a => TypeRepMap f -> Bool Source #
Check if a value of the given type is present in a TypeRepMap
.
>>>
member @Char $ one (Identity 'a')
True>>>
member @Bool $ one (Identity 'a')
False
lookup :: forall a f. Typeable a => TypeRepMap f -> Maybe (f a) Source #
Lookup a value of the given type in a TypeRepMap
.
>>>
x = lookup $ insert (Identity (11 :: Int)) empty
>>>
x :: Maybe (Identity Int)
Just (Identity 11)>>>
x :: Maybe (Identity ())
Nothing
size :: TypeRepMap f -> Int Source #
Get the amount of elements in a TypeRepMap
.
cachedBinarySearch :: Fingerprint -> PrimArray Word64 -> PrimArray Word64 -> Maybe Int Source #
Binary searched based on this article http://bannalia.blogspot.com/2015/06/cache-friendly-binary-search.html with modification for our two-vector search case.
typeFp :: forall a. Typeable a => Fingerprint Source #
toPairList :: TypeRepMap f -> [(Fingerprint, Any)] Source #
deleteByFst :: Eq a => a -> [(a, b)] -> [(a, b)] Source #
Existential wrapper around Typeable
indexed by f
type parameter.
Useful for TypeRepMap
structure creation form list of TF
s.
fromList :: forall f. [TF f] -> TypeRepMap f Source #
Creates TypeRepMap
from a list of TF
s.
>>>
size $ fromList [TF $ Identity True, TF $ Identity 'a']
2
calcFp :: Typeable a => f a -> Fingerprint Source #
fromListPairs :: [(Fingerprint, Any)] -> TypeRepMap f Source #
fromSortedList :: forall a. [a] -> [a] Source #