[Haskell-cafe] Re: Write Haskell as fast as C. [Was: Re: GHC predictability]

Andrew Coppin andrewcoppin at btinternet.com
Fri May 16 15:17:24 EDT 2008

Bryan O'Sullivan wrote:
> Andrew Coppin wrote:
>> On the other hand, this is the anti-theisis of Haskell. We start with a
>> high-level, declarative program, which performs horribly, and end up
>> with a manually hand-optimised blob that's much harder to read but goes
>> way faster.
> Buh?  This is hard to read?

Look closer: it's hardER to read.

  mean xs = sum xs / fromIntegral (length xs)

  mean = go 0 0 n
      go s l x
        | x > m = s / fromIntegra l
        | otherwise = go (s+x) (l+1) (x+1

One version makes it instantly clear, at a glance, what is happening. 
The other requires you to mentally walk round a look, imperative style, 
to figure out what's happening. It's not a *big* deal, but it's unfortunate.

I'm more worried about what happens in less trivial examples. [Let's 
face it, who wants to compute the sum of the numbers from 1 to N?]

More information about the Haskell-Cafe mailing list