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 (Mateusz Kowalczyk)


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

Message: 1
Date: Sat, 16 Feb 2013 16:46:07 +0000
From: Mateusz Kowalczyk <fuuze...@fuuzetsu.co.uk>
Subject: Re: [Haskell-beginners] Stack overflow folding a map
To: beginners@haskell.org
Message-ID: <511fb7cf.4070...@fuuzetsu.co.uk>
Content-Type: text/plain; charset=ISO-8859-1

[1] might help you.

[1] - http://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl%27

Mateusz K.

On 16/02/13 09:13, tcollin371 wrote:
> 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 29
*****************************************

Reply via email to