Re: [Haskell-cafe] strange stack overflow with Data.Map

2005-12-29 Thread Bulat Ziganshin
Hello David, Thursday, December 29, 2005, 3:42:05 AM, you wrote: stats elems = foldl add_elem Map.empty elems DR This program has a space leak and runs out of stack space. I'm guessing DR that I'm being bit here by an unnatural amount of laziness in DR Map.insertWith stack overflows AFAIK is

Re: [Haskell-cafe] strange stack overflow with Data.Map

2005-12-29 Thread Tomasz Zielonka
On Thu, Dec 29, 2005 at 11:22:11AM +0300, Bulat Ziganshin wrote: stack overflows AFAIK is never occur because of laziness, but only because your recursion is not tail-optimized. AFAIK, evaluating a thunk in GHC-compiled code does use the stack - update frames are being put on it. There is a

Re: [Haskell-cafe] strange stack overflow with Data.Map

2005-12-29 Thread Christian Maeder
David Roundy wrote: stats elems = foldl add_elem Map.empty elems add_elem m x = Map.insertWith (+) x 1 m main = print $ stats $ take 100 $ repeat 1 This program has a space leak and runs out of stack space. I'm guessing that I'm being bit here by an unnatural amount of laziness in

Re: [Haskell-cafe] strange stack overflow with Data.Map

2005-12-29 Thread David Roundy
On Thu, Dec 29, 2005 at 01:42:29PM +0100, Christian Maeder wrote: David Roundy wrote: stats elems = foldl add_elem Map.empty elems add_elem m x = Map.insertWith (+) x 1 m main = print $ stats $ take 100 $ repeat 1 This program has a space leak and runs out of stack space. I'm

Re: [Haskell-cafe] strange stack overflow with Data.Map

2005-12-29 Thread David Roundy
On Thu, Dec 29, 2005 at 04:24:02PM +0100, Jean-Philippe Bernardy wrote: On 12/29/05, David Roundy [EMAIL PROTECTED] wrote: On Thu, Dec 29, 2005 at 01:42:29PM +0100, Christian Maeder wrote: David Roundy wrote: stats elems = foldl add_elem Map.empty elems add_elem m x = Map.insertWith

Re: [Haskell-cafe] strange stack overflow with Data.Map

2005-12-29 Thread Cale Gibbard
Laziness and strictness are both important depending on the situation. I'd recommend keeping both variants around. Having to wrap values in an extra data type just to keep laziness sort of defeats the point of Haskell being lazy in the first place. It also makes it somewhat awkward to use in the

[Haskell-cafe] strange stack overflow with Data.Map

2005-12-28 Thread David Roundy
Hi all, I've got a problem that I'm seeing using either Data.Map or Data.IntMap. module Main where import Data.List import qualified Data.IntMap as Map stats elems = foldl add_elem Map.empty elems add_elem m x = Map.insertWith (+) x 1 m main = print $ stats $ take 100 $ repeat 1

Re: [Haskell-cafe] strange stack overflow with Data.Map

2005-12-28 Thread Udo Stenzel
David Roundy wrote: stats elems = foldl add_elem Map.empty elems add_elem m x = Map.insertWith (+) x 1 m [...] I tried defining add_elem m x = let m' = Map.insertWith (+) x 1 m Just num = Map.lookup x m' in seq num m' to force the (+) to be evaluated