Efficient implementation of a dependent map with types as keys


Version on this page:
LTS Haskell 18.28:
Stackage Nightly 2022-02-27:
Latest on Hackage:

See all snapshots typerep-map appears in

MPL-2.0 licensed by Veronika Romashkina, Vladislav Zavialov, Dmitrii Kovanikov
Maintained by Kowainik
This version can be pinned in stack with:typerep-map-,4681

Module documentation for

Used by 1 package in lts-17.2(full list with versions):



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

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



typerep-map uses PVP Versioning. The changelog is available on GitHub. — Apr 18, 2020

  • #83: Support GHC-8.10.
  • #80: Build on 32-bit platforms.
  • #78: Support GHC-8.8.3.
  • #63: Add invariant check.

0.3.2 — Mar 27, 2019

  • #47: Add Eq instance for TypeRepMap using -XQuantifiedConstraints.
  • #70: Bump up to dependent-sum-0.5.


  • #64: Fix segfault in toList.
  • Support GHC 8.4.4 and 8.6.3.


  • #46: Make Show instance for TypeRepMap show keys. Add keys function.
  • #48: Add adjust function for TypeRepMap and TMap.
  • #30: Rewrite fromSortedList to use Array and MutableArray instead of IntMap.


  • #43: Implement IsList instance for TypeRepMap. Add hoistA function.
  • #39: Implement hoistWithKey function. Add map function for TMap.
  • Drop support for ghc-8.0.2.


  • Initially created.