[Haskell-cafe] GHC predictability

Jeff Polakow jeff.polakow at db.com
Tue May 13 15:53:52 EDT 2008


> For example, the natural and naive way to write Andrew's "mean" function
> doesn't involve tuples at all: simply tail recurse with two accumulator
> parameters, and compute the mean at the end.  GHC's strictness analyser
> does the right thing with this, so there's no need for seq, $!, or the
> like.  It's about 3 lines of code.
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?



This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080513/10bd9e68/attachment.htm

More information about the Haskell-Cafe mailing list