[project @ 2005-01-19 22:33:32 by ralf]
[haskell-directory.git] / Data / IntMap.hs
index ce9f3eb..46c6bee 100644 (file)
@@ -137,6 +137,7 @@ import Data.Bits
 import Data.Int
 import Data.Monoid
 import qualified Data.IntSet as IntSet
+import Data.Typeable
 
 {-
 -- just for testing
@@ -146,6 +147,11 @@ import List (nub,sort)
 import qualified List
 -}  
 
+#if __GLASGOW_HASKELL__
+import Data.Generics.Basics
+import Data.Generics.Instances
+#endif
+
 #if __GLASGOW_HASKELL__ >= 503
 import GHC.Word
 import GHC.Exts ( Word(..), Int(..), shiftRL# )
@@ -158,20 +164,8 @@ import Data.Word
 
 infixl 9 \\{-This comment teaches CPP correct behaviour -}
 
-#if __HUGS__
-{--------------------------------------------------------------------
-  Hugs:
-  * Older Hugs doesn't define 'Word'.
-  * Newer Hugs defines 'Word' in the Prelude but no operations.
---------------------------------------------------------------------}
-type Nat = Word32   -- illegal on 64-bit platforms!
-#else
-{--------------------------------------------------------------------
-  'Standard' Haskell
-  * A "Nat" is a natural machine word (an unsigned Int)
---------------------------------------------------------------------}
+-- A "Nat" is a natural machine word (an unsigned Int)
 type Nat = Word
-#endif
 
 natFromInt :: Key -> Nat
 natFromInt i = fromIntegral i
@@ -216,6 +210,23 @@ type Mask   = Int
 type Key    = Int
 
 {--------------------------------------------------------------------
+  A Data instance  
+--------------------------------------------------------------------}
+
+#if __GLASGOW_HASKELL__
+
+-- This instance preserves data abstraction at the cost of inefficiency.
+-- We omit reflection services for the sake of data abstraction.
+
+instance Data a => Data (IntMap a) where
+  gfoldl f z im = z fromList `f` (toList im)
+  toConstr _    = error "toConstr"
+  gunfold _ _   = error "gunfold"
+  dataTypeOf _  = mkNorepType "Data.IntMap.IntMap"
+
+#endif
+
+{--------------------------------------------------------------------
   Query
 --------------------------------------------------------------------}
 -- | /O(1)/. Is the map empty?
@@ -979,6 +990,13 @@ showMap (x:xs)
     showElem (k,x)  = shows k . showString ":=" . shows x
   
 {--------------------------------------------------------------------
+  Typeable
+--------------------------------------------------------------------}
+
+#include "Typeable.h"
+INSTANCE_TYPEABLE1(IntMap,intMapTc,"IntMap")
+
+{--------------------------------------------------------------------
   Debugging
 --------------------------------------------------------------------}
 -- | /O(n)/. Show the tree that implements the map. The tree is shown