Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Stack overflow folding a map (tcollin371)
----------------------------------------------------------------------
Message: 1
Date: Sat, 16 Feb 2013 04:13:14 -0500 (EST)
From: tcollin371 <[email protected]>
Subject: [Haskell-beginners] Stack overflow folding a map
To: Hask <[email protected]>
Message-ID:
<3549819.1361005995070.javamail.r...@elwamui-muscovy.atl.sa.earthlink.net>
Content-Type: text/plain; charset=UTF-8
I've been playing around with Haskell on and off for a while, and am getting a
"Stack space overflow" that I can't seem to correct. I have a map containing
about 2 million items. Actually, it's a map keyed off of an Int where the
element is another map keyed off of a string that has three Ints as its data.
The number of top level maps is pretty small (< 50), and the maps held by them
hold a lot of entries.
I want to walk through all of the entries and gather some statistics, but I
keep getting the stack overflow. I worked down my test to an inner and outer
fold that just counts the entries, and I still get the stack overflow. I added
'seq' calls to make sure that the count isn't building up a bunch of undone
operations, and I'm using foldlWithKey, and have also tried foldlWithKey' with
the same result.
I get the count in my main function and immediately print it out. Here is the
relevant code:
outputIfNotFilteredCount1 :: Int -> KeyMap -> PuzzleMapRecord -> Int
outputIfNotFilteredCount1 inCount key entry
= seq inCount (inCount + 1)
outputDatabaseCount1 :: Int -> Int -> InnerDB -> Int
outputDatabaseCount1 inCount smndCount innerDB
= seq inCount (inCount + outCount)
where
outCount
= Map.foldlWithKey' outputIfNotFilteredCount1 0 innerDB
main = do
...
let
count = Map.foldlWithKey' outputDatabaseCount1 0 resultDB
putStrLn $ "Database entries:" ++ (show count)
Any thoughts on why this is running out of stack space?
-Truman
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 56, Issue 28
*****************************************