aboutsummaryrefslogtreecommitdiff
path: root/src/Map.hs
diff options
context:
space:
mode:
authorpanne <unknown>2005-01-15 18:44:48 +0000
committerpanne <unknown>2005-01-15 18:44:48 +0000
commit914ccdce1b9923f7fc8f75b3bdb188192291ac9b (patch)
tree975e0562f4810a89fa7fcc181885f99bd5f5f3c7 /src/Map.hs
parente8f54f255a7295fc0da368390706b1ae5d90268c (diff)
[haddock @ 2005-01-15 18:44:45 by panne]
Make Haddock compile again after the recent base package changed. The Map/Set legacy hell has been factored out, so that all modules can simply use the new non-deprecated interfaces. Probably a lot of things can be improved by a little bit of Map/Set/List algebra, this can be done later if needed. Small note: Currently the list of instances in HTML code is reversed. This will hopefully be fixed later.
Diffstat (limited to 'src/Map.hs')
-rw-r--r--src/Map.hs64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/Map.hs b/src/Map.hs
new file mode 100644
index 00000000..4209798b
--- /dev/null
+++ b/src/Map.hs
@@ -0,0 +1,64 @@
+module Map (
+ Map,
+ member, lookup, findWithDefault,
+ empty,
+ insert, insertWith,
+ union, unionWith, unions,
+ elems,
+ fromList, fromListWith,
+ toAscList
+) where
+
+import Prelude hiding ( lookup )
+import qualified Set
+
+#if __GLASGOW_HASKELL__ < 503
+import FiniteMap
+#elif __GLASGOW_HASKELL__ < 603
+import Data.FiniteMap
+#else
+import Data.Map
+#endif
+
+#if __GLASGOW_HASKELL__ < 603
+type Map k a = FiniteMap k a
+
+member :: Ord k => k -> Map k a -> Bool
+member = elemFM
+
+lookup :: Ord k => k -> Map k a -> Maybe a
+lookup = flip lookupFM
+
+findWithDefault :: Ord k => a -> k -> Map k a -> a
+findWithDefault a k m = lookupWithDefaultFM m a k
+
+empty :: Map k a
+empty = emptyFM
+
+insert :: Ord k => k -> a -> Map k a -> Map k a
+insert k a m = addToFM m k a
+
+insertWith :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
+insertWith c k a m = addToFM_C c m k a
+
+union :: Ord k => Map k a -> Map k a -> Map k a
+union = flip plusFM
+
+unionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
+unionWith c l r = plusFM_C c r l
+
+unions :: Ord k => [Map k a] -> Map k a
+unions = foldr plusFM emptyFM
+
+elems :: Map k a -> [a]
+elems = eltsFM
+
+fromList :: Ord k => [(k,a)] -> Map k a
+fromList = listToFM
+
+fromListWith :: Ord k => (a -> a -> a) -> [(k,a)] -> Map k a
+fromListWith = flip addListToFM_C emptyFM
+
+toAscList :: Map k a -> [(k,a)]
+toAscList = fmToList
+#endif