main :: IO ()
main = do { content <- readFile "in.txt"
     ; let -- change this following type annotation
           -- to change different type of the dictionary
           -- dict :: DM.Map S.ByteString Int
           -- dict :: IM.IntMap Int
           dict :: Trie Int
           dict = fromList (map parse_a_line  (lines content))
..
   where  parse_a_line :: String -> (Key,Int)
          parse_a_line line = case words line of
                 [key,val] -> (key,read val)
                 _ -> error " parse error.  "

Maps tend to be strict in their keys, but not in their values.
You might be storing a lot of thunks with unparsed Strings instead of plain Int values.

Something like this might make a difference wrt memory usage:

          [key,val] -> ((,) key) $! (read val)

Hth,
Claus

Here is a comparison of memory usage

Map     : 345 MB
IntMap : 146 MB
Trie     : 282 MB
Python : 94 MB

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to