Skip to content
⚡️Efficient implementation of Map with types as keys
Haskell Nix
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmark [#70] Bump dependent-map to 0.5 (#71) Mar 27, 2019
src/Data Introduce invariant check. (#63) Aug 18, 2019
typerep-extra-impls/Data/TypeRep Improve benchmarks. (#61) Oct 19, 2018
.gitignore [#75] Bump up to primitive (#76) Jul 1, 2019
.hlint.yaml [#6] Add README, refresh docs, refactor, add hlint (#18) Jul 9, 2018
.travis.yml [#73] Bump up to GHC 8.6.5 (#74) May 18, 2019 [#47] Add Eq instance to TypeRepMap using QuantifiedConstraints (#72) Mar 27, 2019
LICENSE Create the project Dec 15, 2017
shell.nix Fix segfault in 'toList' (#65) Jan 21, 2019


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

ghci> res = lookup tm

ghci> res :: Maybe Int
Just 42

ghci> res :: Maybe Bool
Just True

ghci> res :: Maybe String

ghci> lookup (insert "hello" tm) :: Maybe String
Just "hello"

ghci> member @Int tm

ghci> tm' = delete @Int tm

ghci> member @Int tm'


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
You can’t perform that action at this time.