[turn atom into a simple newtype of an int.
John Meacham <john@repetae.net>**20060420010510] hunk ./Atom.hs 1
-module Atom(Atom, toPackedString, Atom.toString, atomIndex, fromStringIO, fromString, fromPackedStringIO, dumpAtomTable, ToAtom(..), FromAtom(..), intToAtom) where
+module Atom(
+    Atom(),
+    Atom.toString,
+    FromAtom(..),
+    ToAtom(..),
+    atomIndex,
+    dumpAtomTable,
+    fromPackedStringIO,
+    fromString,
+    fromStringIO,
+    intToAtom,
+    toPackedString
+    ) where
hunk ./Atom.hs 36
-reverseTable :: HT.HashTable Int Atom
+reverseTable :: HT.HashTable Int PackedString
hunk ./Atom.hs 44
-data Atom = Atom {-# UNPACK #-} !Int !PackedString
-    deriving(Typeable, Data)
+newtype Atom = Atom Int
+    deriving(Typeable, Data,Eq,Ord)
hunk ./Atom.hs 48
-    showsPrec _ (Atom _ ps) = showsPS ps
+    showsPrec _ atom = (toString atom ++)
hunk ./Atom.hs 51
-    readsPrec p s = [ (fromString x,y) |  (x,y) <- readsPrec p s]
+    readsPrec _ s = [ (fromString s,"") ]
+    --readsPrec p s = [ (fromString x,y) |  (x,y) <- readsPrec p s]
hunk ./Atom.hs 54
-toPackedString (Atom _ ps) = ps
-toString (Atom _ ps) = unpackPS ps
-atomIndex (Atom x _) = x
+toPackedString atom = atomToPS atom
+toString atom = unpackPS $ toPackedString atom
+atomIndex (Atom x) = x
hunk ./Atom.hs 84
---instance FromAtom Int where
---    fromAtom (Atom i _) = i
-
-instance Eq Atom where
-    Atom x _ == Atom y _ = x == y
-    Atom x _ /= Atom y _ = x /= y
-
-instance Ord Atom where
-    compare (Atom x _) (Atom y _) = compare x y
-    Atom x _ <= Atom y _ = x <= y
-    Atom x _ >= Atom y _ = x >= y
-    Atom x _ < Atom y _ = x < y
-    Atom x _ > Atom y _ = x > y
hunk ./Atom.hs 97
-        let a = Atom i ps
+        let a = Atom i
hunk ./Atom.hs 99
-        HT.insert reverseTable i a
+        HT.insert reverseTable i ps
hunk ./Atom.hs 107
-    mapM_ putStrLn [ show i ++ " " ++ show ps  | (_,Atom i ps) <- sort x]
+    mapM_ putStrLn [ show i ++ " " ++ show ps  | (ps,Atom i) <- sort x]
hunk ./Atom.hs 112
-    Just x -> return (return x)
+    Just _ -> return (return $ Atom i)
hunk ./Atom.hs 115
+atomToPS :: Atom -> PackedString
+atomToPS (Atom i) = unsafePerformIO $  HT.lookup reverseTable i >>= \x -> case x of
+    Just ps -> return ps
+    Nothing -> return $ error $ "atomToPS: " ++ show i
+