[Haskell-cafe] GHC predictability
Dan Doel
dan.doel at gmail.com
Tue May 13 16:22:48 EDT 2008
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
More information about the Haskell-Cafe
mailing list