@@ -1,3 +1,8 @@
2+#if __GLASGOW_HASKELL__
3+{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
1-- | An 'OMap' behaves much like a 'Map', with all the same asymptotics, but
6-- | An 'OMap' behaves much like a 'Map', with all the same asymptotics, but
2-- also remembers the order that keys were inserted.
7-- also remembers the order that keys were inserted.
3module Data.Map.Ordered
8module Data.Map.Ordered
@@ -34,6 +39,10 @@ import Data.Map.Util (Index, Tag, maxTag, minTag, nextHigherTag, nextLowerTag, r
34import Prelude hiding (filter, lookup, null)
39import Prelude hiding (filter, lookup, null)
35import qualified Data.Map as M
40import qualified Data.Map as M
42+#if __GLASGOW_HASKELL__
37data OMap k v = OMap !(Map k (Tag, v)) !(Map Tag (k, v))
46data OMap k v = OMap !(Map k (Tag, v)) !(Map Tag (k, v))
39-- | Values are produced in insertion order, not key order.
48-- | Values are produced in insertion order, not key order.
@@ -43,6 +52,32 @@ instance ( Ord k, Ord v) => Ord (OMap k v) where compare = compare `on`
43instance ( Show k, Show v) => Show (OMap k v) where showsPrec = showsPrecList assocs
52instance ( Show k, Show v) => Show (OMap k v) where showsPrec = showsPrecList assocs
44instance (Ord k, Read k, Read v) => Read (OMap k v) where readsPrec = readsPrecList fromList
53instance (Ord k, Read k, Read v) => Read (OMap k v) where readsPrec = readsPrecList fromList
55+#if __GLASGOW_HASKELL__
56+# if __GLASGOW_HASKELL__ >= 708
57+deriving instance Typeable OMap
59+deriving instance Typeable2 OMap
62+-- This instance preserves data abstraction at the cost of inefficiency.
63+-- We provide limited reflection services for the sake of data abstraction.
65+instance (Data k, Data a, Ord k) => Data (OMap k a) where
66+ gfoldl f z m = z fromList `f` assocs m
67+ toConstr _ = fromListConstr
68+ gunfold k z c = case constrIndex c of
71+ dataTypeOf _ = oMapDataType
72+ dataCast2 f = gcast2 f
74+fromListConstr :: Constr
75+fromListConstr = mkConstr oMapDataType "fromList" [] Prefix
77+oMapDataType :: DataType
78+oMapDataType = mkDataType "Data.Map.Ordered.Map" [fromListConstr]
46infixr 5 <|, |< -- copy :
81infixr 5 <|, |< -- copy :
47infixl 5 >|, |>
82infixl 5 >|, |>