️Efficient implementation of Map with types as keys
Go to file
Veronika Romashkina 5d78b489b2
[#87] Move tests to hspec (#88)
Resolves #87
2020-04-18 17:15:01 +01:00
.github [#83] Support GHC-8.10 (#84) 2020-04-18 14:16:20 +01:00
benchmark [#70] Bump dependent-map to 0.5 (#71) 2019-03-27 13:27:27 +08:00
src/Data [#83] Support GHC-8.10 (#84) 2020-04-18 14:16:20 +01:00
test [#87] Move tests to hspec (#88) 2020-04-18 17:15:01 +01:00
typerep-extra-impls/Data/TypeRep [#83] Support GHC-8.10 (#84) 2020-04-18 14:16:20 +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 [#83] Support GHC-8.10 (#84) 2020-04-18 14:16:20 +01:00
CHANGELOG.md [#83] Support GHC-8.10 (#84) 2020-04-18 14:16:20 +01:00
LICENSE [#83] Support GHC-8.10 (#84) 2020-04-18 14:16:20 +01:00
README.md [#73] Bump up to GHC 8.6.5 (#74) 2019-05-18 11:14:31 +08:00
stack.yaml [#87] Move tests to hspec (#88) 2020-04-18 17:15:01 +01:00
typerep-map.cabal [#87] Move tests to hspec (#88) 2020-04-18 17:15:01 +01:00

typerep-map

electricity Build status Hackage Stackage LTS Stackage Nightly MIT 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 this 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
DMap TypeRep 517.5 ns 779.9 ns
typerep-map 205.3 ns 187.2 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