On Mon, Jun 25, 2007 at 08:53:18AM -0700, Dave Bayer wrote:
> It continues to appear to me that "ghc -Wall -Werror" doesn't support
> small Int constants without a per-use penalty, measured in code length.
Why not use "ghc -Wall -Werror -fno-warn-defaulting", maybe with
default(Int)? It removes the potential problems that justified
coding the warning, and turns off the warning.
By the way, using Integer for exponents really shouldn't be less efficient -
but it seems it is.
The code for (^) should be something like this:
{-# INLINE ^ #-}
n ^ m = case toInteger m of
S# i -> powerInt# n i
J# a p -> powerGmp n a p
(With powerInt# and powerGmp specialized on various types
of n, when there is something to gain).
Then the standard optimizations (inlining, static instance
selection, more inlining, and case of constructor)
should turn n^3 into the same code whether 3 is Int or Integer.
Perhaps GHC.Real needs to be sprinkled with more pragmas.
> Am I the only one blessed/cursed with a vision of how proponents of
> "practical" languages would have a field day with this? Perhaps I'm
> reading too many blogs.
Seeing as it only happens if you specifically ask the compiler
to be as annoying as possible, no reasonable person should take
this much farther than complaining about the GHC warning options.
After all, the type system and purity we claim are generally good
things are still around whatever options you pass, and none of the
justifications for them have much to say one way or the other on
this sort of compiler warning.
I think nobody will argue if you suggest GHC shouldn't complain
about defaulting if only one of the candidate types is actually
usable. It's rather like typeclasses with -fallow-overlapping-instaces.
Brandon