From 914ccdce1b9923f7fc8f75b3bdb188192291ac9b Mon Sep 17 00:00:00 2001 From: panne Date: Sat, 15 Jan 2005 18:44:48 +0000 Subject: [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. --- src/Map.hs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/Map.hs (limited to 'src/Map.hs') 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 -- cgit v1.2.3