on 32ebb33 help sign in
typerep-map/src/Data/TypeRepMap.hs
71 lines 1.9 kB history raw
1{-# LANGUAGE NoImplicitPrelude #-}
3-- | A version of 'Data.TMap.TMap' parametrized by an interpretation @f@. This
4-- sort of parametrization may be familiar to users of @vinyl@ records.
5--
6-- @'TypeRepMap' f@ is a more efficient replacement for @DMap
7-- 'Type.Reflection.TypeRep' f@ (where @DMap@ is from the @dependent-map@
8-- package).
9--
10-- Here is an example of using 'Prelude.Maybe' as an interpretation, with a
11-- comparison to 'Data.TMap.TMap':
12--
13-- @
14-- 'Data.TMap.TMap' 'TypeRepMap' 'Prelude.Maybe'
15-- -------------- -------------------
16-- Int -> 5 Int -> Just 5
17-- Bool -> True Bool -> Nothing
18-- Char -> \'x\' Char -> Just \'x\'
19-- @
20--
21-- In fact, a 'Data.TMap.TMap' is defined as 'TypeRepMap'
22-- 'Data.Functor.Identity'.
23--
24-- Since 'Type.Reflection.TypeRep' is poly-kinded, the interpretation can use
25-- any kind for the keys. For instance, we can use the 'GHC.TypeLits.Symbol'
26-- kind to use 'TypeRepMap' as an extensible record:
27--
28-- @
29-- newtype Field name = F (FType name)
30--
31-- type family FType (name :: Symbol) :: Type
32-- type instance FType "radius" = Double
33-- type instance FType "border-color" = RGB
34-- type instance FType "border-width" = Double
35--
36-- 'TypeRepMap' Field
37-- --------------------------------------
38-- "radius" -> F 5.7
39-- "border-color" -> F (rgb 148 0 211)
40-- "border-width" -> F 0.5
41-- @
42--
43module Data.TypeRepMap
44 ( -- * Map type
45 TypeRepMap()
47 -- * Construction
48 , empty
49 , one
51 -- * Modification
52 , insert
53 , delete
54 , adjust
55 , hoist
56 , hoistA
57 , hoistWithKey
58 , unionWith
59 , union
61 -- * Query
62 , lookup
63 , member
64 , size
65 , keys
67 -- * 'IsList'
68 , WrapTypeable (..)
69 ) where
71import Data.TypeRepMap.Internal