[Haskell-cafe] help with Haskell performance

Felipe Lessa felipe.lessa at gmail.com
Sat Nov 7 16:29:17 EST 2009

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.


More information about the Haskell-Cafe mailing list