summaryrefslogtreecommitdiff
path: root/IntMapClass.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-08-12 16:04:01 -0400
committerjoe <joe@jerkface.net>2014-08-12 16:04:01 -0400
commitebfbdcd09b92a55b6c9f5a1f7feaa4f98c2236ba (patch)
tree32d1eb49260359433ba5bcc976880383fe701ba2 /IntMapClass.hs
parentb042e6bae6cf60e10c13ddf48eecf9eb3cdd44c5 (diff)
IntMapClass experiment
Diffstat (limited to 'IntMapClass.hs')
-rw-r--r--IntMapClass.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/IntMapClass.hs b/IntMapClass.hs
new file mode 100644
index 0000000..49e1125
--- /dev/null
+++ b/IntMapClass.hs
@@ -0,0 +1,41 @@
1{-# LANGUAGE CPP,
2 FlexibleContexts,
3 MultiParamTypeClasses,
4 GeneralizedNewtypeDeriving,
5 DeriveDataTypeable #-}
6module IntMapClass where
7
8import qualified Data.IntMap.Strict as IntMap
9import Data.IntMap.Strict ( IntMap )
10import Data.Typeable ( Typeable )
11import Data.Data ( Data )
12import Data.Foldable ( Foldable )
13import Data.Traversable ( Traversable )
14import Data.Monoid ( Monoid )
15import Control.DeepSeq ( NFData )
16#if MIN_VERSION_base(4,7,0)
17import Data.Coerce
18#else
19class Coercible a b where coerce :: a -> b
20#endif
21
22newtype IMap k a = IMap (IntMap a)
23 deriving
24 ( Functor
25 , Typeable
26 , Foldable
27 , Traversable
28 , Eq
29 , Data
30 , Ord
31 , Read
32 , Show
33 , Monoid
34 , NFData
35 )
36
37adapt_m_k :: Coercible k Int => (IntMap a -> Int -> x) -> IMap k a -> k -> x
38adapt_m_k f (IMap m) k = f m (coerce k)
39
40(!) :: Coercible k Int => IMap k a -> k -> a
41(!) = adapt_m_k (IntMap.!)