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'`

`>>>`

1`size tm`

`>>>`

False`member @Bool tm`

`>>>`

True`member @Char tm`

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`

`>>>`

Just 11`x :: Maybe Int`

`>>>`

Nothing`x :: Maybe ()`

member :: forall a. Typeable a => TMap -> Bool Source #

Check if a value of the given type is present in a `TMap`

.

`>>>`

True`member @Char $ one 'a'`

`>>>`

False`member @Bool $ one 'a'`

keys :: TMap -> [SomeTypeRep] Source #

Returns the list of `SomeTypeRep`

s from keys.