Ah, you're right. Then we need a foldl' insertWith with a strict plus.

2009/11/8 Felipe Lessa <[email protected]>:
> On Sun, Nov 08, 2009 at 12:15:57AM +0300, Eugene Kirpichov wrote:
>> Here, you should not use Map.fromListWith (+) because Map is not
>> strict in its entries and you end up having big fat thunks there.
>> You should use Map.fromListWith plus where x `plus` y = x `seq` y `seq` x+y.
>
> fromListWith is implemented with insertWithKey; is defining plus
> like above enough?  I would guess that we need fromListWith'
> implemented with insertWithKey'.
>
> The problem is that it will build a thunk (x `plus` y) and your
> seq's only say that whenever you evaluate that thunk you'll
> evaluate the arguments as well.  If the thunk itself isn't
> needed, it won't be evaluated.
>
> --
> Felipe.
> _______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Eugene Kirpichov
Web IR developer, market.yandex.ru
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to