[make Info.Info more efficient and give it a real 'Showable' instance
John Meacham <john@repetae.net>**20050930003742] hunk ./E/SSimplify.hs 47
-    deriving(Typeable)
+    deriving(Typeable,Show)
hunk ./Info/Binary.hs 6
+import Atom
hunk ./Info/Binary.hs 11
-import PackedString
hunk ./Info/Binary.hs 13
-data Binable = forall a . (Typeable a, Binary a) => Binable a
+data Binable = forall a . (Typeable a, Binary a, Show a) => Binable a
hunk ./Info/Binary.hs 18
-cb x = (packString (show (toDyn x)), Binable x)
+createTyp :: Typeable a => a -> Atom
+createTyp x = toAtom (show (typeOf x))
+newEntry typ x = Entry { entryThing = toDyn x, entryString = show x, entryType = typ }
+
+cb x = (createTyp x, Binable x)
hunk ./Info/Binary.hs 30
-putDyn :: BinHandle -> (PackedString,Dynamic,Binable) -> IO ()
+putDyn :: BinHandle -> (Atom,Dynamic,Binable) -> IO ()
hunk ./Info/Binary.hs 41
-    (ps::PackedString) <- get h
+    (ps::Atom) <- get h
hunk ./Info/Binary.hs 44
-        (Binable (_ :: a)) -> ((get h :: IO a) >>= return . toDyn)
+        (Binable (_ :: a)) -> do
+            x <- get h :: IO a
+            return $ newEntry ps x
hunk ./Info/Binary.hs 51
-                let ps = packString $ show d
+                let ps = entryType d
hunk ./Info/Binary.hs 53
-                return (ps,d,x)
-              )  ds
+                return (ps,entryThing d,x)
+              )  (Map.elems ds)
hunk ./Info/Binary.hs 60
-        return (Info xs)
+        return (Info $ Map.fromList [ (entryType x, x) | x <- xs])
hunk ./Info/Info.hs 1
-module Info.Info where
+module Info.Info(T,Info(..),Entry(..),Info.Info.lookup,insertWith,insert,singleton,delete, fetch, extend, empty) where
hunk ./Info/Info.hs 7
-import qualified Data.Set as Set
+import qualified Data.Map as Map
hunk ./Info/Info.hs 9
-
+import Atom
+import GenUtil
hunk ./Info/Info.hs 17
-newtype Info = Info [Dynamic]
+data Entry = Entry {
+    entryThing   :: Dynamic,
+    entryString  :: String,
+    entryType    :: Atom
+    }
+
+instance Eq Entry where
+    a == b = entryType a == entryType b
+
+instance Show Entry where
+    showsPrec _ x = showString (entryString x)
+
+instance Ord Entry where
+    compare a b = compare (entryType a) (entryType b)
+
+newtype Info = Info (Map.Map Atom Entry)
hunk ./Info/Info.hs 36
-    show (Info ds) = show ds
+    show (Info ds) = show (sortUnder (show . entryType) (Map.elems ds))
hunk ./Info/Info.hs 44
-    mappend (Info as) (Info bs) = Info ([ b | b <- bs, not (show b `Set.member` ass) ] ++ as) where
-        ass = Set.fromList $ map show as
+    mappend (Info as) (Info bs) = Info (Map.union as bs)
hunk ./Info/Info.hs 48
-lookup (Info ds)  = case msum (map fromDynamic ds) of
-    Just x -> return x
-    Nothing -> fail $ "Info: could not find " ++ show (typeOf (undefined :: a))
+lookup (Info mp) = do
+    let typ = createTyp (undefined :: a)
+    case Map.lookup typ mp of
+        Just Entry { entryThing = x } -> case fromDynamic x of
+            Just x -> return x
+            Nothing -> error "Info.lookup: this can't happen"
+        Nothing -> fail $ "Info: could not find " ++ show typ
hunk ./Info/Info.hs 56
-insertWith :: (Typeable a) => (a -> a -> a) -> a -> Info -> Info
+
+createTyp :: Typeable a => a -> Atom
+createTyp x = toAtom (show (typeOf x))
+
+insertWith :: (Show a,Typeable a) => (a -> a -> a) -> a -> Info -> Info
+insertWith f x (Info mp) = Info (Map.insert typ (newEntry typ nx) mp) where
+    typ = createTyp x
+    nx = case Map.lookup typ mp of
+        Nothing -> x
+        Just Entry { entryThing = d } -> f x (fromDyn d (error "can't happen"))
+
+
+newEntry typ x = Entry { entryThing = toDyn x, entryString = show x, entryType = typ }
+
+{-
hunk ./Info/Info.hs 76
+-}
hunk ./Info/Info.hs 78
-insert :: (Typeable a) => a -> Info -> Info
+insert :: (Show a,Typeable a) => a -> Info -> Info
hunk ./Info/Info.hs 81
-singleton :: (Typeable a) => a -> Info
+singleton :: (Show a,Typeable a) => a -> Info
hunk ./Info/Info.hs 90
-extend :: (Monoid a, Typeable a) => a -> Info -> Info
+extend :: (Show a,Monoid a, Typeable a) => a -> Info -> Info
hunk ./Info/Info.hs 94
-empty = Info []
+empty = Info Map.empty
hunk ./Info/Types.hs 14
-    deriving(Typeable,Show,Binary,Monoid)
+    deriving(Typeable,Show,Eq,Binary,Monoid)
hunk ./SelfTest.hs 5
+import qualified Data.Set as Set
hunk ./SelfTest.hs 123
-        t = Arity 3
+        t = Properties (Set.singleton prop_INLINE)