[project @ 2005-03-15 13:38:27 by simonmar]
[ghc-base.git] / Data / FiniteMap.hs
index ee18419..8bafafc 100644 (file)
@@ -8,6 +8,8 @@
 -- Stability   :  provisional
 -- Portability :  portable
 --
+-- NOTE: Data.FiniteMap is DEPRECATED, please use "Data.Map" instead.
+--
 -- A finite map implementation, derived from the paper:
 --        /Efficient sets: a balancing act/, S. Adams,
 --        Journal of functional programming 3(4) Oct 1993, pp553-562
@@ -38,7 +40,9 @@
 #define OUTPUTABLE_key {--}
 #endif
 
-module Data.FiniteMap (
+module Data.FiniteMap
+  {-# DEPRECATED "Please use Data.Map instead." #-} 
+  (
        -- * The @FiniteMap@ type
        FiniteMap,              -- abstract type
 
@@ -84,9 +88,14 @@ module Data.FiniteMap (
 #endif
     ) where
 
+import Prelude -- necessary to get dependencies right
+
 import Data.Maybe ( isJust )
 #ifdef __GLASGOW_HASKELL__
 import GHC.Base
+import Data.Typeable
+import Data.Generics.Basics
+import Data.Generics.Instances
 #endif
 
 #ifdef __HADDOCK__
@@ -115,6 +124,7 @@ import Bag  ( foldBag )
 #endif /* not GHC */
 
 
+
 -- ---------------------------------------------------------------------------
 -- The signature of the module
 
@@ -187,7 +197,7 @@ minusFM             :: (Ord key OUTPUTABLE_key) => FiniteMap key elt1 -> FiniteMap key elt2
 -- key.
 intersectFM    :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
 
--- | Returns the interesction of two mappings, using the specified
+-- | Returns the intersection of two mappings, using the specified
 -- combination function to combine values.
 intersectFM_C  :: (Ord key OUTPUTABLE_key) => (elt1 -> elt2 -> elt3)
                           -> FiniteMap key elt1 -> FiniteMap key elt2 -> FiniteMap key elt3
@@ -283,6 +293,23 @@ instance (Show k, Show e) => Show (FiniteMap k e) where
 instance Functor (FiniteMap k) where
   fmap f = mapFM (const f)
 
+#if __GLASGOW_HASKELL__
+
+#include "Typeable.h"
+INSTANCE_TYPEABLE2(FiniteMap,arrayTc,"FiniteMap")
+
+-- This instance preserves data abstraction at the cost of inefficiency.
+-- We omit reflection services for the sake of data abstraction.
+
+instance (Data a, Data b, Ord a) => Data (FiniteMap a b) where
+  gfoldl f z fm = z listToFM `f` (fmToList fm)
+  toConstr _    = error "toConstr"
+  gunfold _ _   = error "gunfold"
+  dataTypeOf _  = mkNorepType "Data.FiniteMap.FiniteMap"
+
+#endif
+
+
 -- ---------------------------------------------------------------------------
 -- Adding to and deleting from @FiniteMaps@