PROPOSAL: Restrict the type of (^), (^^), and add genericPower,
genericPower'
Henning Thielemann
lemming at henning-thielemann.de
Sat Nov 17 16:13:54 EST 2007
On Sat, 17 Nov 2007, David Benbennick wrote:
> I vote against this proposal.
>
> On 11/17/07, Ian Lynagh <igloo at earth.li> wrote:
> > In my experience this would remove 99.9% of all defaulting (mostly where
> > you write things like x^12 and 8^12), which means it's easier to get
> > -Wall clean without having to put :: Int annotations everywhere.
>
> I agree that is a benefit (making it easier to avoid warnings), but in
> my opinion it is a tiny benefit.
Let me guess - you don't use -Wall. :-) Warnings are not the problem,
warnings point to a problem. The problem here is, that the compiler has to
guess a type, because it cannot be infered from other operands.
> The inverse proposal has the same benefit, and doesn't require a
> change to GHC: just add intPower to your own code, and use it wherever
> you want. If you are unhappy with the idea of using intPower, perhaps
> you understand why I'm unhappy with the prospect of having to use
> genericPower.
Question: How often did you need the genericity of Haskell 98 (^) ? That
is, how often do you call (^) with a non-constant exponent and how often
is the exponent constant?
If I have (^) with variable exponents too often in the code, I suspect
that I missed some optimizations like (iterate (x*) 1).
I have done (semi-automatically) some statistics on my mathematical stuff
in Haskell, namely
http://darcs.haskell.org/htam/src
(^^) used with exponents
(1-j)
(n2-1)
n
pred n
(^) used with variable exponents
i
j
m
n
n
n
n
degree xs
degree xs
degree ys
(n2-1)
mod n 2
mod (p+1) 2
(^) used with constant exponents
2: 169 times
3: 31 times
4: 9 times
5: 10 times
6: 3 times
7: 2 times
8: 1 times
9: 1 times
If I search for '::Int', the most results are exponents of (^), others are
from enumerations like [(0::Int)..].
More information about the Libraries
mailing list