️Efficient implementation of Map with types as keys
Go to file
mniip 88b9ac5a23
Add keysWith and toListWith (#106)
* Add keysWith and toListWith

* Add some tests
2021-03-14 12:15:21 +00:00
.github [#102] Update default branch to main (#103) 2020-11-06 17:23:49 +00:00
benchmark [#90] Check more ghc warnings through ghc-options (#91) 2020-04-18 19:51:04 +01:00
src/Data Add keysWith and toListWith (#106) 2021-03-14 12:15:21 +00:00
test Add keysWith and toListWith (#106) 2021-03-14 12:15:21 +00:00
typerep-extra-impls/Data/TypeRep [#90] Check more ghc warnings through ghc-options (#91) 2020-04-18 19:51:04 +01:00
.gitignore [#75] Bump up to primitive 0.7.0.0 (#76) 2019-07-01 23:53:52 +08:00
.hlint.yaml [#6] Add README, refresh docs, refactor, add hlint (#18) 2018-07-09 12:59:31 +08:00
.stylish-haskell.yaml Create .stylish-haskell.yaml 2018-09-30 21:07:31 +08:00
.travis.yml Build only with stack on Travis CI (#89) 2020-04-18 19:07:17 +01:00
appveyor.yml Build on Windows CI, update badges (#86) 2020-04-18 17:37:42 +01:00
CHANGELOG.md [#102] Update default branch to main (#103) 2020-11-06 17:23:49 +00:00
LICENSE [#83] Support GHC-8.10 (#84) 2020-04-18 14:16:20 +01:00
README.md [#102] Update default branch to main (#103) 2020-11-06 17:23:49 +00:00
stack.yaml [#87] Move tests to hspec (#88) 2020-04-18 17:15:01 +01:00
typerep-map.cabal Remove dependency on containers (#93) 2020-10-10 22:10:34 +01:00

typerep-map

logo

GitHub CI Build status Windows build status Hackage Stackage LTS Stackage Nightly MPL-2.0 license

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.

For the more details on the implementation see the following blog post:

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 ghc-8.8.3 ghc-8.10.1
DMap TypeRep 517.5 ns 779.9 ns 1.559 μs 1.786 μs
typerep-map 205.3 ns 187.2 ns 190.1 ns 169.1 ns
ghc-8.2.2 ghc-8.4.3
DMap 8.2.2 DMap 8.4.3
TMap 8.2.2 TMap 8.4.3