[Haskell-cafe] A tale of three shootout entries
Simon Peyton-Jones
simonpj at microsoft.com
Wed Nov 28 03:41:53 EST 2007
| There may well have been changes to the strictness analyser that make
| some of the bangs (or most) unnecessary now. Also, its very likely
| I didn't check all combinations of strict and lazy arguments for the
| optimal evaluation strategy :)
|
| If it seems to be running consitently faster (and producing better Core
| code), by all means submit. I don't think this is a ghc bug or anything
| like that though: just overuse of bangs, leading to unnecessary work.
You might think that unnecessary bangs shouldn't lead to unnecessary work -- if GHC knows it's strict *and* you bang the argument, it should still only be evaluated once. But it can happen. Consider
f !xs = length xs
Even though 'length' will evaluate its argument, f nevertheless evaluates it too. Bangs say "evaluate it now", like seq, because we may be trying to control space usage. In this particular case it's silly, because the *first* thing length does is evaluate its argument, but that's not true of every strict function.
That's why I say it'd be good to have well-characterised examples. It *may* be something like what I describe. Or it may be a silly omission somewhere.
Simon
More information about the Haskell-Cafe
mailing list