optimization in the report's prelude, again

Timmy Douglas tdouglas@home.com
Tue, 23 Jan 2001 21:09:05 -0600

well, I'm a newbie and I was looking through the prelude to try to
learn some more haskell and I came across the sample definition of the
(^) operator on page 98. i saw a post for optimization, but and it
got mostly negative replies so i'll go the other way.

if we are writing for clarity and not efficency as it says, then would
it be better to write it as something like

n ^ e | n >= 0 = product $ take (e+1) (1 : repeat n)
_ ^ _ = error "negative exponent"

well, i could care less, but i have nothing better to do so i thought
i'd just ask if this was ok technique or something.

or maybe someone can tell me if there is like an order of "clearest
ways"... for example, using pattern matching if convenient first, then
using standard functions, then list comp., then guards, etc. because i
sometimes think that filter might be clearer as:

filter' f list = [ item | item <- list, f item]

rather than using guards... oh well, enough ranting.

thanks for replies.