1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
{-# LANGUAGE CPP,
FlexibleContexts,
MultiParamTypeClasses,
GeneralizedNewtypeDeriving,
DeriveDataTypeable #-}
module IntMapClass where
import qualified Data.IntMap.Strict as IntMap
import Data.IntMap.Strict ( IntMap )
import Data.Typeable ( Typeable )
import Data.Data ( Data )
import Data.Foldable ( Foldable )
import Data.Traversable ( Traversable )
import Data.Monoid ( Monoid )
import Control.DeepSeq ( NFData )
#if MIN_VERSION_base(4,7,0)
import Data.Coerce
#else
class Coercible a b where coerce :: a -> b
#endif
newtype IMap k a = IMap (IntMap a)
deriving
( Functor
, Typeable
, Foldable
, Traversable
, Eq
, Data
, Ord
, Read
, Show
, Monoid
, NFData
)
adapt_m_k :: Coercible k Int => (IntMap a -> Int -> x) -> IMap k a -> k -> x
adapt_m_k f (IMap m) k = f m (coerce k)
(!) :: Coercible k Int => IMap k a -> k -> a
(!) = adapt_m_k (IntMap.!)
|