Safe Haskell | None |
---|---|
Language | Haskell2010 |
TMap
is a heterogeneous data structure similar in its essence to
Map
with types as keys, where each value has the type of its key.
Here is an example of a TMap
with a comparison to Map
:
Map
String
String
TMap
-------------------- ----------------- "Int" -> "5"Int
-> 5 "Bool" -> "True"Bool
->True
"Char" -> "'x'"Char
-> 'x'
The runtime representation of TMap
is an array, not a tree. This makes
lookup
significantly more efficient.
Synopsis
- type TMap = TypeRepMap Identity
- empty :: TMap
- one :: forall a. Typeable a => a -> TMap
- insert :: forall a. Typeable a => a -> TMap -> TMap
- delete :: forall a. Typeable a => TMap -> TMap
- unionWith :: (forall x. x -> x -> x) -> TMap -> TMap -> TMap
- union :: TMap -> TMap -> TMap
- map :: (forall a. Typeable a => a -> a) -> TMap -> TMap
- adjust :: Typeable a => (a -> a) -> TMap -> TMap
- lookup :: forall a. Typeable a => TMap -> Maybe a
- member :: forall a. Typeable a => TMap -> Bool
- size :: TMap -> Int
- keys :: TMap -> [SomeTypeRep]
Map type
type TMap = TypeRepMap Identity Source #
TMap
is a special case of TypeRepMap
when the interpretation is
Identity
.
Construction
Modification
delete :: forall a. Typeable a => TMap -> TMap Source #
Delete a value from a TMap
.
size (delete @a tm) <= size tm
member @a (delete @a tm) == False
>>>
tm = delete @Bool $ insert True $ one 'a'
>>>
size tm
1>>>
member @Bool tm
False>>>
member @Char tm
True
unionWith :: (forall x. x -> x -> x) -> TMap -> TMap -> TMap Source #
The union of two TMap
s using a combining function.
adjust :: Typeable a => (a -> a) -> TMap -> TMap Source #
Update a value with the result of the provided function.
Query
lookup :: forall a. Typeable a => TMap -> Maybe a Source #
Lookup a value of the given type in a TMap
.
>>>
x = lookup $ insert (11 :: Int) empty
>>>
x :: Maybe Int
Just 11>>>
x :: Maybe ()
Nothing
member :: forall a. Typeable a => TMap -> Bool Source #
Check if a value of the given type is present in a TMap
.
>>>
member @Char $ one 'a'
True>>>
member @Bool $ one 'a'
False
keys :: TMap -> [SomeTypeRep] Source #
Returns the list of SomeTypeRep
s from keys.