@hackage typerep-map0.1.0
Efficient implementation of a dependent map with types as keys
Categories
License
MIT
Maintainer
xrom.xkov@gmail.com
Links
Versions
Deprecated
Tested Compilers
Dependencies (7)
- base >=4.9 && <5
- containers
- ghc-prim
- primitive >=0.6.4 Show all…
Dependents (11)
@hackage/ihp, @hackage/ihp-mail, @hackage/compaREST, @hackage/ihp-datasync, @hackage/hedgehog-gen, @hackage/imm, Show all…
typerep-map
typerep-map introduces TMap and TypeRepMap — data structures like Map, but where types serve as keys, and values have the types specified in the corresponding key spots.
Usage example
ghci> import Data.TMap
ghci> tm = insert True $ one (42 :: Int)
ghci> size tm
2
ghci> res = lookup tm
ghci> res :: Maybe Int
Just 42
ghci> res :: Maybe Bool
Just True
ghci> res :: Maybe String
Nothing
ghci> lookup (insert "hello" tm) :: Maybe String
Just "hello"
ghci> member @Int tm
True
ghci> tm' = delete @Int tm
ghci> member @Int tm'
False
Benchmarks
Tables below contain comparision with DMap TypeRep of ten lookup operations
on structure with size 10^4:
| ghc-8.2.2 | ghc-8.4.3 | |
|---|---|---|
DMap TypeRep |
517.5 ns | 779.9 ns |
typerep-map |
205.3 ns | 187.2 ns |
| ghc-8.2.2 | ghc-8.4.3 |
|---|---|
![]() |
![]() |
![]() |
![]() |



