on main help sign in
typerep-map/src/Data/TypeRepMap.hs
81 lines 2.0 kB history raw
1{-# LANGUAGE NoImplicitPrelude #-}
3{- |
4Copyright: (c) 2017-2020 Kowainik
5SPDX-License-Identifier: MPL-2.0
6Maintainer: Kowainik <xrom.xkov@gmail.com>
8A 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 , alter
61 , hoist
62 , hoistA
63 , hoistWithKey
64 , unionWith
65 , union
66 , intersectionWith
67 , intersection
69 -- * Query
70 , lookup
71 , member
72 , size
73 , keys
74 , keysWith
75 , toListWith
77 -- * 'IsList'
78 , WrapTypeable (..)
79 ) where
81import Data.TypeRepMap.Internal