
13 May
2008
13 May
'08
8:22 p.m.
On Tuesday 13 May 2008, Jeff Polakow wrote:
Is this the code you mean?
meanNat = go 0 0 where go s n [] = s / n go s n (x:xs) = go (s+x) (n+1) xs
If so, bang patterns are still required bang patterns in ghc-6.8.2 to run in constant memory:
meanNat = go 0 0 where go s n [] = s / n go !s !n (x:xs) = go (s+x) (n+1) xs
Is there some other way to write it so that ghc will essentially insert the bangs for me?
It works fine here when compiled with -O or better. Perhaps that should be a tip in the book? Make sure you're compiling with optimizations. :) -- Dan