on 5d096df help sign in
60 lines 1.8 kB history raw
1{-# LANGUAGE TypeFamilies #-}
2-- Must come after TypeFamilies, otherwise it is re-enabled.
3-- MonoLocalBinds enabled by TypeFamilies causes perf regressions in general.
4{-# LANGUAGE NoMonoLocalBinds #-}
5-- |
6-- Module : Streamly.Internal.Data.IsMap
7-- Copyright : (c) 2022 Composewell Technologies
8-- License : BSD-3-Clause
9-- Maintainer : streamly@composewell.com
10-- Stability : experimental
11-- Portability : GHC
13module Streamly.Internal.Data.IsMap (IsMap(..)) where
15import Data.Kind (Type)
16import Data.Map.Strict (Map)
18import qualified Data.IntMap.Strict as IntMap
19import qualified Data.Map.Strict as Map
21-- XXX Try unpacked-containers
23class IsMap f where
24 type Key f :: Type
26 mapEmpty :: f a
27 mapAlterF :: Functor g =>
28 (Maybe a -> g (Maybe a)) -> Key f -> f a -> g (f a)
29 -- These can be implemented in terms of alterF itself
30 mapLookup :: Key f -> f a -> Maybe a
31 mapInsert :: Key f -> a -> f a -> f a
32 mapDelete :: Key f -> f a -> f a
33 mapUnion :: f a -> f a -> f a
34 mapNull :: f a -> Bool
35 mapTraverseWithKey ::
36 Applicative t => (Key f -> a -> t b) -> f a -> t (f b)
38instance Ord k => IsMap (Map k) where
39 type Key (Map k) = k
41 mapEmpty = Map.empty
42 mapAlterF = Map.alterF
43 mapLookup = Map.lookup
44 mapInsert = Map.insert
45 mapDelete = Map.delete
46 mapUnion = Map.union
47 mapNull = Map.null
48 mapTraverseWithKey = Map.traverseWithKey
50instance IsMap IntMap.IntMap where
51 type Key IntMap.IntMap = Int
53 mapEmpty = IntMap.empty
54 mapAlterF = IntMap.alterF
55 mapLookup = IntMap.lookup
56 mapInsert = IntMap.insert
57 mapDelete = IntMap.delete
58 mapUnion = IntMap.union
59 mapNull = IntMap.null
60 mapTraverseWithKey = IntMap.traverseWithKey