import Data.Int
import Data.Monoid
import qualified Data.IntSet as IntSet
+import Data.Typeable
{-
-- just for testing
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# )
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
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?
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