typerep-map: Efficient implementation of a dependent map with types as keys

[ data, data-structures, library, mpl, types ] [ Propose Tags ] [ Report a vulnerability ]

A dependent map from type representations to values of these types.

Here is an illustration of such a map:

    TMap
---------------
 Int  -> 5
 Bool -> True
 Char -> 'x'

In addition to TMap, we provide TypeRepMap parametrized by a vinyl-style interpretation. This data structure is equivalent to DMap TypeRep, but with significantly more efficient lookups.


[Skip to Readme]

library typerep-map

Modules

[Index] [Quick Jump]

  • Data
    • Data.TMap
    • Data.TypeRepMap
      • Data.TypeRepMap.Internal

library typerep-map:typerep-extra-impls

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.2.0, 0.3.0, 0.3.1, 0.3.2, 0.3.3.0, 0.4.0.0, 0.5.0.0, 0.6.0.0 (info)
Change log CHANGELOG.md
Dependencies base (>=4.10 && <4.18), containers (>=0.5.10.2 && <0.7), deepseq (>=1.4 && <1.5), ghc-prim (>=0.5.1.1 && <0.10), primitive (>=0.7.0 && <0.8), vector (>=0.12.0.1 && <0.14) [details]
Tested with ghc ==8.2.2, ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.4, ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.4, ghc ==9.4.2
License MPL-2.0
Copyright 2017-2022 Kowainik
Author Veronika Romashkina, Vladislav Zavialov, Dmitrii Kovanikov
Maintainer Kowainik <xrom.xkov@gmail.com>
Category Data, Data Structures, Types
Home page https://github.com/kowainik/typerep-map
Bug tracker https://github.com/kowainik/typerep-map/issues
Source repo head: git clone https://github.com/kowainik/typerep-map.git
Uploaded by vrom911 at 2022-11-02T20:33:13Z
Distributions NixOS:0.6.0.0
Reverse Dependencies 5 direct, 16 indirect [details]
Downloads 20013 total (65 in the last 30 days)
Rating 2.5 (votes: 3) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for typerep-map-0.6.0.0

[back to package description]

typerep-map

logo

GitHub CI Hackage 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