[Haskell-cafe] Best idiom for avoiding Defaulting warnings with ghc -Wall -Werror ??

Dave Bayer bayer at cpw.math.columbia.edu
Mon Jun 25 11:03:35 EDT 2007

On Jun 25, 2007, at 4:48 AM, Simon Peyton-Jones wrote:

> The intention is that it should be straightforward to suppress  
> warnings.

> Simply add a type signature for 'z', or for the naked 3 in z's  
> definition.

I constructed my example from larger modules peppered with small  
integer constants; such signatures would become a significant  
percentage of the code. I was hoping for a solution whose code size  
is at worst linear in the number of distinct integer constants used,  
not the number of times they are used. I'd like to avoid redefining  
operators if I can help it.

Given that there are entire languages in common use that don't  
support Integer, I don't see why "ghc -Wall -Werror" can't become  
such a language when it sees

> default (Int)

Instead it issues defaulting warnings even in the presence of this  

I couldn't find a way to add a type signature once for each small  
integer constant I plan to use; it would appear to me that

> 2,3 :: Int

by itself is not legal Haskell. The best I can do is to instead write

> i2,i3 :: Int
> (i2,i3) = (2,3)

which imposes a per-use penalty of one character per use, and is less  
readable than simply unrolling the constants in each use. In other  
words, if I can't write x^3, I find x*x*x more transparent than x^i3  
or x^(3::Int).

Despite my participation in a broader discussion, my hope in starting  
this thread was to understand how to most elegantly use the specific  
programming language "ghc -Wall -Werror".

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.

On Jun 25, 2007, at 4:48 AM, Simon Peyton-Jones wrote:
> I think it matters what type is chosen, because it affects the  
> output of the program; it's good practice to be explicit about what  
> type you want, at each site where defaulting is applied.

I agree, so I'm glad I asked here rather than reporting warnings in  
the presence of "default (Int)" as a bug.

Unless I misunderstand and it is already possible, I'd now prefer a  
language extension that allows the explicit declarations

> 2,3 :: Int

once for each affected numeric literal.


More information about the Haskell-Cafe mailing list