[Haskell-cafe] help with Haskell performance
ekirpichov at gmail.com
Sat Nov 7 16:51:44 EST 2009
Ah, you're right. Then we need a foldl' insertWith with a strict plus.
2009/11/8 Felipe Lessa <felipe.lessa at gmail.com>:
> 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.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
Web IR developer, market.yandex.ru
More information about the Haskell-Cafe