Copyright | (c) 2016-2017 Tao He |
---|---|
License | MIT |
Maintainer | sighingnow@gmail.com |
Safe Haskell | Safe |
Language | Haskell2010 |
Updatable heterogeneous map.
> let a = add"a" (1 :: Int) nil > a [a = 1] > let b = update
"a" (+1) a > b [a = 2] > let c = add"b" (Nothing :: Maybe Float) b > c [b = Nothing, a = 2] > set
"b" (Just 128) c [b = Just 128.0, a = 2]
- data HMap (kvs :: [KV *])
- data KV v = Symbol := v
- class ShowKV (kvs :: [KV *]) where
- class MatchKVList (kvs1 :: [KV *]) (kvs2 :: [KV *]) where
- nil :: HMap '[]
- add :: forall k v kvs. No ~ FindKV k v kvs => v -> HMap kvs -> HMap ((k := v) ': kvs)
- add' :: forall k v kvs. Proxy k -> v -> HMap kvs -> HMap ((k := v) ': kvs)
- (.+.) :: forall k v kvs. No ~ FindKV k v kvs => v -> HMap kvs -> HMap ((k := v) ': kvs)
- get :: forall (k :: Symbol) v kvs. InDict k v kvs => HMap kvs -> v
- (.->.) :: forall (k :: Symbol) v kvs. InDict k v kvs => HMap kvs -> v
- update :: forall (k :: Symbol) v kvs. InDict k v kvs => (v -> v) -> HMap kvs -> HMap kvs
- set :: forall k v kvs. InDict k v kvs => v -> HMap kvs -> HMap kvs
- mergeTo :: forall (kvs1 :: [KV *]) (kvs2 :: [KV *]). MatchKVList kvs1 kvs2 => HMap kvs1 -> HMap kvs2 -> HMap kvs2
- dump :: forall kvs. ShowKV kvs => HMap kvs -> [(String, String)]
HMap type definition
Type level constraints and operators
class MatchKVList (kvs1 :: [KV *]) (kvs2 :: [KV *]) where Source #
Merge the first KVList into the second one.
mergeTo' :: HMap kvs1 -> HMap kvs2 -> HMap kvs2 Source #
Update all values in the first HMap into the second KVList.
MatchKVList ([] (KV *)) kvs2 Source # | |
(MatchKVList kvs1 kvs2, InDict k v kvs2) => MatchKVList ((:) (KV *) ((:=) * k v) kvs1) kvs2 Source # | |
Operations on HMap.
add :: forall k v kvs. No ~ FindKV k v kvs => v -> HMap kvs -> HMap ((k := v) ': kvs) Source #
Add a key-value pair into the HMap (via TypeApplications).
add' :: forall k v kvs. Proxy k -> v -> HMap kvs -> HMap ((k := v) ': kvs) Source #
Add a key-value pair into the HMap (via TypeApplications).
FIXME should have a 'No ~ FindKV k v kvs
constraint here.
(.+.) :: forall k v kvs. No ~ FindKV k v kvs => v -> HMap kvs -> HMap ((k := v) ': kvs) infix 8 Source #
Infix version of add
.
get :: forall (k :: Symbol) v kvs. InDict k v kvs => HMap kvs -> v Source #
Get the value of an existing key.
(.->.) :: forall (k :: Symbol) v kvs. InDict k v kvs => HMap kvs -> v infix 7 Source #
Infix version of get
.
update :: forall (k :: Symbol) v kvs. InDict k v kvs => (v -> v) -> HMap kvs -> HMap kvs Source #
Update the value of an existing key.
set :: forall k v kvs. InDict k v kvs => v -> HMap kvs -> HMap kvs Source #
Set the value of an existing key.