Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Stack overflow folding a map (tcollin371)


----------------------------------------------------------------------

Message: 1
Date: Sun, 17 Feb 2013 23:27:56 -0800 (GMT-08:00)
From: tcollin371 <tcollin...@earthlink.net>
Subject: Re: [Haskell-beginners] Stack overflow folding a map
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Message-ID:
        
<26727168.1361172476789.javamail.r...@elwamui-huard.atl.sa.earthlink.net>
        
Content-Type: text/plain; charset=UTF-8

It turns out that the problem isn't the counting code in the fold operations, 
but instead seems to be lazy evaluation that's happening as the map is built.  
If I run through the count operation every few thousand inserts, then I don't 
get the stack overflow operation.

-Truman


-----Original Message-----
>From: tcollin371 <tcollin...@earthlink.net>
>Sent: Feb 16, 2013 1:13 AM
>To: Hask <beginners@haskell.org>
>Subject: [Haskell-beginners] Stack overflow folding a map
>
>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
>Beginners@haskell.org
>http://www.haskell.org/mailman/listinfo/beginners




------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 56, Issue 30
*****************************************

Reply via email to