[Haskell-cafe] GHC optimisations

Twan van Laarhoven twanvl at gmail.com
Wed Aug 22 15:14:19 EDT 2007

Stefan O'Rear wrote:
> On Wed, Aug 22, 2007 at 06:36:15PM +0100, Neil Mitchell wrote:
>>>If Num obeys ring axioms, fromInteger is a perfectly fine
>>>ring-homomorphism. (It's also the first or second homomorphism taught.)
>>Does Int obey these axioms? I'm thinking that assuming properties
>>about things such as numbers is very likely to go wrong very quickly.
>>Monads you might be able to get away with, Numbers you probably can't.
> Int does obey the axioms, it's the classical ring ℤ[4294967296].
> Double, however, does not:

But Double is already quite badly behaved:
 > let x = 1e20
 > Prelude> 1 + (x - x)
 > 1.0
 > Prelude> (1 + x) - x
 > 0.0

Using the fromInteger (and fromRational) axioms should only *increase* 
precission, I don't see how that is such a bad thing.

Also, as far as I can see GHC already does this optimizations if the 
type is specialized to Double. Except for the fact that the PrelRules 
rules don't seem to fire, because the constants get floated out.


More information about the Haskell-Cafe mailing list