>Qxd$QC/sdeK{93/{KA]&T@gir{b8(rd5/zL85UcsTGty!z9Nx%Z+0e193YVEXFcWdM.]+uyVYA6WN 
        Nn]tdh-oQ]/#\R;Vts^}W]a%+%VqSEAu
Date: Fri, 24 Oct 1997 11:23:16 -0400
From: Alastair Reid <[EMAIL PROTECTED]>
Sender: [EMAIL PROTECTED]
Precedence: bulk
Resent-Date:  Fri, 24 Oct 1997 16:33:49 +0100
Resent-From: [EMAIL PROTECTED]
Resent-To: [EMAIL PROTECTED]
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"


The argument has always been that you'll use Integer as the default.
Once you have written and tested your program, you might choose to
switch to using Int if you can convince yourself that you don't use
integers above 2^29-1.  How you do this is up to you.  

The tedious, but safe, way is to do all the proofs by hand. 

The reckless way is to run your program on a few examples and check
 the answers against your original program.

The middle ground is to define a new type which will perform runtime
 overflow checks.  This approach requires two tricks: 
 1) You have to write range-checking versions of all the usual
    Int functions.
 2) You have to provide instances for Eq, Ord, Num, etc so that you
    can continue to write things like "1 + 2 >= x" in you programs.

 The good news is that Mark Jones has already done all the work for
 you - the Number library distributed as part of Hugs does it all!

Alastair Reid

ps If you prefer modular arithmetic, you might like to use the type
   Int32 - the type of guaranteed 32 bit integers.  
   Details of Int32 and other libraries can be found in
   ftp://haskell.org/pub/reid/libs971022/libs.html.  Feedback is 
   very welcome.

> I wonder, why Haskell does not check/report the overflow for Int?
> 
> 
> For the Haskell implementation, it is natural to have the  Int 
> arithmetic cost much less (about 5 times) than  Integer.
> 
> Therefore, for the applications like the polynomial arithmetics
> (and many others) that represent a power product as 
> 
> "newtype PP = PP [Integer] "   or   "newtype PP' = PP' [Int] "
> 
> it worths to preserve both PP and PP'.
> 
> PP' is considerably cheaper in running, and PP is generic.
> 
> Unfortunately, PP' is incorrect.
> 
> For example,   x^(2^n) --> x^0,   if  2^n > maximal_Int.
> 
> For the algebra, it would be better to 
>                    *break in such case with the overflow message*.
> 
> With this, the researcher runs the faster program and does not 
> risk to get the incorrect result.
> 
> Setting things like   newtype Int' = I' Int  
> in application and programming arithmetics in Haskell, probably,
> would not do. This will run slow. 
> Besides,   (I' 2)+x   looks worse than   2+x.
> So
> 1. is this good for Haskell to perform the Int arithmetic modulo 
>    maximal_Int ?
> 2. in what way could it provide also Int' ?
> 
> 
> 
> ------------------
> Sergey Mechveliani
> 
> [EMAIL PROTECTED]




Reply via email to