[switch Info to list based representation
John Meacham <john@repetae.net>**20060720013007] hunk ./Info/Binary.hs 1
-module Info.Binary(putInfo, getInfo) where
+module Info.Binary(putInfo, Info.Binary.getInfo) where
hunk ./Info/Binary.hs 24
-newEntry typ x = Entry { entryThing = toDyn x, entryString = show x, entryType = typ }
+newEntry x = Entry { entryThing = toDyn x, entryString = show x, entryType = typeOf x }
hunk ./Info/Binary.hs 51
-            return $ newEntry ps x
+            return $ newEntry x
hunk ./Info/Binary.hs 56
-    get h = getInfo h
+    get h = Info.Binary.getInfo h
hunk ./Info/Binary.hs 61
-            let ps = entryType d
+            let ps = toAtom (show $ entryType d)
hunk ./Info/Binary.hs 64
-          )  (Map.elems ds)
+          ) ds
hunk ./Info/Binary.hs 71
-    return (Info $ Map.fromList [ (entryType x, x) | x <- xs])
+    return (Info  [ x | x <- xs])
hunk ./Info/Info.hs 5
+    HasInfo(..),
hunk ./Info/Info.hs 9
+    limit,
hunk ./Info/Info.hs 25
-import qualified Data.Map as Map
+import qualified Data.List as List
hunk ./Info/Info.hs 38
-    entryType    :: Atom
+    entryType    :: TypeRep
hunk ./Info/Info.hs 48
-    compare a b = compare (entryType a) (entryType b)
+    compare a b = compare (show $ entryType a) (show $ entryType b)
hunk ./Info/Info.hs 50
-newtype Info = Info (Map.Map Atom Entry)
+newtype Info = Info [Entry]
hunk ./Info/Info.hs 54
-    show (Info ds) = show (sortUnder (show . entryType) (Map.elems ds))
+    show (Info ds) = show (sortUnder (show . entryType) ds)
hunk ./Info/Info.hs 62
-    mappend (Info as) (Info bs) = Info (Map.union as bs)
+    mappend (Info as) (Info bs) = Info (List.union as bs)
+
+class HasInfo a where
+    getInfo :: a -> Info
+    modifyInfo :: (Info -> Info) -> a -> a
+
+instance HasInfo Info where
+    getInfo = id
+    modifyInfo f x = f x
hunk ./Info/Info.hs 75
-    let typ = createTyp (undefined :: a)
-    case Map.lookup typ mp of
-        Just Entry { entryThing = x } -> case fromDynamic x of
+    let typ = typeOf (undefined :: a)
+        f [] = fail $ "Info: could not find " ++ show typ
+        f (x:xs) | entryType x == typ = case fromDynamic (entryThing x) of
hunk ./Info/Info.hs 80
-        Nothing -> fail $ "Info: could not find " ++ show typ
+        f (_:xs) = f xs
+    f mp
hunk ./Info/Info.hs 88
-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"))
+insertWith f newx (Info mp) = Info (g mp) where
+    g [] = [newEntry newx]
+    g (x:xs) | entryType x == typ = newEntry (f newx (fromDyn (entryThing x) (error "can't happen"))):xs
+             | otherwise = x:g xs
+    typ = typeOf newx
hunk ./Info/Info.hs 95
-newEntry typ x = Entry { entryThing = toDyn x, entryString = show x, entryType = typ }
+newEntry :: (Typeable a,Show a) => a -> Entry
+newEntry x = Entry { entryThing = toDyn x, entryString = show x, entryType = typeOf x }
hunk ./Info/Info.hs 100
-insert x info = insertWith const x info
+insert newx (Info nfo) = Info $ newEntry newx:f nfo where
+    f [] = []
+    f (x:xs) | entryType x == typ = xs
+             | otherwise = x:f xs
+    typ = typeOf newx
hunk ./Info/Info.hs 126
-delete x = let typ = createTyp x in  \ (Info mp) -> Info (Map.delete typ mp)
+delete x info = deleteTyp (typeOf x) info
+
+deleteTyp :: TypeRep -> Info -> Info
+deleteTyp typ (Info mp) = Info (f mp) where
+    f [] = []
+    f (x:xs) | entryType x == typ = xs
+             | otherwise = x:f xs
+
+limit :: [TypeRep] -> Info -> Info
+limit trs (Info mp) = Info (f mp) where
+    f (x:xs) | entryType x `elem` trs = x:f xs
+             | otherwise = f xs
+    f [] = []
hunk ./Info/Info.hs 144
-member x (Info s) = Map.member (createTyp x) s
+member x (Info s) = f s where
+    typ = typeOf x
+    f [] = False
+    f (x:xs) | entryType x == typ = True
+             | otherwise = f xs
hunk ./Info/Info.hs 154
-empty = Info Map.empty
-
-{-
-
-newtype Info = Info (Map.Map TypeRep Dynamic)
-    deriving(Monoid,HasSize)
-
-
-lookup :: (Monad m,Typeable a) => Info -> m a
-lookup (Info fm) :: m a = case Map.lookup tr fm of
-        Just x -> return (fromDyn x undefined :: a)
-        Nothing -> fail $ "Info: could not find " ++ show tr
-    where tr = typeOf (undefined :: a)
-
-
-fetch :: (Monoid a, Typeable a) => Info -> a
-fetch info = maybe mempty id  (Info.lookup info)
-
-insert :: (Typeable a) => a -> Info -> Info
-insert x (Info fm) = Info (Map.insert (typeOf x) (toDyn x) fm)
-
-insertWith :: (Typeable a) => (a -> a -> a) -> a -> Info -> Info
-insertWith f x (Info fm) = Info (Map.adjust (\y -> toDyn $ f x (fromDyn y undefined)) (typeOf x)  fm)
-
-extend :: (Monoid a, Typeable a) => a -> Info -> Info
-extend x info = insertWith mappend x info
+empty = Info []
hunk ./Info/Info.hs 156
--}