diff options
author | joe <joe@jerkface.net> | 2014-08-12 16:04:01 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-08-12 16:04:01 -0400 |
commit | ebfbdcd09b92a55b6c9f5a1f7feaa4f98c2236ba (patch) | |
tree | 32d1eb49260359433ba5bcc976880383fe701ba2 /IntMapClass.hs | |
parent | b042e6bae6cf60e10c13ddf48eecf9eb3cdd44c5 (diff) |
IntMapClass experiment
Diffstat (limited to 'IntMapClass.hs')
-rw-r--r-- | IntMapClass.hs | 41 |
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 #-} | ||
6 | module IntMapClass where | ||
7 | |||
8 | import qualified Data.IntMap.Strict as IntMap | ||
9 | import Data.IntMap.Strict ( IntMap ) | ||
10 | import Data.Typeable ( Typeable ) | ||
11 | import Data.Data ( Data ) | ||
12 | import Data.Foldable ( Foldable ) | ||
13 | import Data.Traversable ( Traversable ) | ||
14 | import Data.Monoid ( Monoid ) | ||
15 | import Control.DeepSeq ( NFData ) | ||
16 | #if MIN_VERSION_base(4,7,0) | ||
17 | import Data.Coerce | ||
18 | #else | ||
19 | class Coercible a b where coerce :: a -> b | ||
20 | #endif | ||
21 | |||
22 | newtype 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 | |||
37 | adapt_m_k :: Coercible k Int => (IntMap a -> Int -> x) -> IMap k a -> k -> x | ||
38 | adapt_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.!) | ||