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

[ data, data-structures, library, mit, types ] [ Propose Tags ]

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]
Versions [faq] 0.1.0, 0.2.0, 0.3.0, 0.3.1
Change log CHANGELOG.md
Dependencies base (>=4.10 && <5), containers (>=0.5.10.2 && <0.7), deepseq (==1.4.*), ghc-prim (>=0.5.1.1 && <0.6), primitive (>=0.6.4 && <0.7) [details]
License MIT
Copyright 2017-2019 Kowainik
Author Kowainik, Vladislav Zavialov
Maintainer xrom.xkov@gmail.com
Revised Revision 2 made by shersh at Tue Jan 22 07:46:34 UTC 2019
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 shersh at Mon Jan 21 20:54:39 UTC 2019
Distributions LTSHaskell:0.3.1, NixOS:0.3.1, Stackage:0.3.1
Downloads 246 total (40 in the last 30 days)
Rating 2.5 (votes: 3) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-01-21 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees


Readme for typerep-map-0.3.1

[back to package description]

typerep-map

electricity Hackage Build status 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