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
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
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
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
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
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
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
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