[project @ 2000-05-10 10:58:15 by sewardj]
authorsewardj <unknown>
Wed, 10 May 2000 10:58:15 +0000 (10:58 +0000)
committersewardj <unknown>
Wed, 10 May 2000 10:58:15 +0000 (10:58 +0000)
Undo revision 1.34 of Prelude.hs, ie, reinstate fromDouble in class
Fractional (in standalone mode).  This reduces by a factor of 6 the
number of enters required for some simple expressions,
for example    1.0 :: Double.

ghc/lib/hugs/PrelPrim.hs
ghc/lib/hugs/Prelude.hs

index ebbdb2c..811fa6a 100644 (file)
@@ -84,7 +84,7 @@ module PrelPrim (
     Real(toRational),
 --  Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
     Integral(quot, rem, div, mod, quotRem, divMod, even, odd, toInteger, toInt),
-    Fractional((/), recip, fromRational), fromDouble,
+    Fractional((/), recip, fromRational, fromDouble),
     Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
              asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
     RealFrac(properFraction, truncate, round, ceiling, floor),
@@ -307,14 +307,12 @@ class (Num a) => Fractional a where
     (/)          :: a -> a -> a
     recip        :: a -> a
     fromRational :: Rational -> a
+    fromDouble   :: Double -> a
 
     -- Minimal complete definition: fromRational and ((/) or recip)
     recip x       = 1 / x
     x / y         = x * recip y
 
-fromDouble :: Fractional a => Double -> a
-fromDouble n = fromRational (toRational n)
-
 class (Fractional a) => Floating a where
     pi                  :: a
     exp, log, sqrt      :: a -> a
@@ -930,10 +928,12 @@ realFloatToRational x = (m%1)*(b%1)^^n
 instance Fractional Float where
     (/)           = primDivideFloat
     fromRational  = rationalToRealFloat
+    fromDouble    = primDoubleToFloat
 
 instance Fractional Double where
     (/)          = primDivideDouble
     fromRational = rationalToRealFloat
+    fromDouble x = x
 
 rationalToRealFloat x = x'
  where x'    = f e
@@ -1115,6 +1115,7 @@ instance Integral a => Fractional (Ratio a) where
     (x:%y) / (x':%y')   = (x*y') % (y*x')
     recip (x:%y)        = if x < 0 then (-y) :% (-x) else y :% x
     fromRational (x:%y) = fromInteger x :% fromInteger y
+    fromDouble          = doubleToRatio
 
 -- Hugs optimises code of the form fromRational (doubleToRatio x)
 doubleToRatio :: Integral a => Double -> Ratio a
index a9c71f8..65fe98e 100644 (file)
@@ -68,7 +68,7 @@ module Prelude (
     Real(toRational),
 --  Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
     Integral(quot, rem, div, mod, quotRem, divMod, even, odd, toInteger, toInt),
-    Fractional((/), recip, fromRational), fromDouble,
+    Fractional((/), recip, fromRational, fromDouble),
     Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
              asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
     RealFrac(properFraction, truncate, round, ceiling, floor),