From 43a4952481d2617a863dc7965bb9de929e3c7792 Mon Sep 17 00:00:00 2001 From: sewardj Date: Mon, 14 Feb 2000 11:12:29 +0000 Subject: [PATCH] [project @ 2000-02-14 11:12:29 by sewardj] Remove fromDouble from class Fractional, and make it standalone. This matches GHC. I don't think this is strictly necessary, but Hugs refers to fromDouble during desugaring and I prefer to avoid possible mishaps. --- ghc/interpreter/lib/Prelude.hs | 11 +++-------- ghc/lib/hugs/Prelude.hs | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/ghc/interpreter/lib/Prelude.hs b/ghc/interpreter/lib/Prelude.hs index 729a3de..9fcb210 100644 --- a/ghc/interpreter/lib/Prelude.hs +++ b/ghc/interpreter/lib/Prelude.hs @@ -84,8 +84,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), - 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), @@ -227,13 +226,13 @@ 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 - fromDouble = fromRational . toRational x / y = x * recip y +fromDouble :: Fractional a => Double -> a +fromDouble n = fromRational (toRational n) class (Fractional a) => Floating a where pi :: a @@ -851,13 +850,10 @@ 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 @@ -1039,7 +1035,6 @@ 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 diff --git a/ghc/lib/hugs/Prelude.hs b/ghc/lib/hugs/Prelude.hs index 729a3de..9fcb210 100644 --- a/ghc/lib/hugs/Prelude.hs +++ b/ghc/lib/hugs/Prelude.hs @@ -84,8 +84,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), - 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), @@ -227,13 +226,13 @@ 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 - fromDouble = fromRational . toRational x / y = x * recip y +fromDouble :: Fractional a => Double -> a +fromDouble n = fromRational (toRational n) class (Fractional a) => Floating a where pi :: a @@ -851,13 +850,10 @@ 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 @@ -1039,7 +1035,6 @@ 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 -- 1.7.10.4