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