apfelmus wrote:
Andrew Coppin wrote:
Look closer: it's hardER to read.
mean xs = sum xs / fromIntegral (length xs)
mean = go 0 0 n
where
go s l x
| x > m = s / fromIntegral 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?]
Hm, it seems like you're expecting magic, aren't you?
Well, obviously it would be nice, wouldn't it? ;-)
Of course the first equation is easier to read, but it's no surprise
that this may actually be slower. Like the imperative bubblesort is
easier to read than the imperative quicksort but far slower.
I'm just saying, I prefer it when somebody posts some tiny snippet of
Haskell that does the same thing as a 40-line C program, and then show
how using some novel technique they just invented, the Haskell version
actually outperforms C even though it's more reasable and more
maintainable. Hey, who *wouldn't* like to have their cake and eat it
too? :-)
But yeah, I get the point. Everybody wants me to be quiet and go away.
So I'll go be quiet now...
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe