From 1d4b441d9184e2364277c1f85745e49655b35ad6 Mon Sep 17 00:00:00 2001 From: qrczak Date: Thu, 22 Feb 2001 16:48:25 +0000 Subject: [PATCH] [project @ 2001-02-22 16:48:24 by qrczak] Since fromInt was degraded to a function, do the same with toInt. --- ghc/lib/std/CPUTime.lhs | 3 +-- ghc/lib/std/Numeric.lhs | 4 ++-- ghc/lib/std/PrelByteArr.lhs | 3 +-- ghc/lib/std/PrelCTypes.lhs | 3 +-- ghc/lib/std/PrelCTypesISO.lhs | 3 +-- ghc/lib/std/PrelInt.lhs | 11 +++-------- ghc/lib/std/PrelNum.lhs | 6 +++--- ghc/lib/std/PrelReal.lhs | 9 +++++---- ghc/lib/std/PrelST.lhs | 7 +++---- ghc/lib/std/PrelWord.lhs | 15 ++++----------- ghc/lib/std/Prelude.lhs | 7 +++---- ghc/lib/std/Random.lhs | 5 ++--- ghc/lib/std/cbits/CTypes.h | 8 +++----- 13 files changed, 32 insertions(+), 52 deletions(-) diff --git a/ghc/lib/std/CPUTime.lhs b/ghc/lib/std/CPUTime.lhs index df37a04..9478bdc 100644 --- a/ghc/lib/std/CPUTime.lhs +++ b/ghc/lib/std/CPUTime.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: CPUTime.lhs,v 1.28 2001/02/22 13:17:58 simonpj Exp $ +% $Id: CPUTime.lhs,v 1.29 2001/02/22 16:48:24 qrczak Exp $ % % (c) The University of Glasgow, 1995-2000 % @@ -24,7 +24,6 @@ import PrelGHC ( indexIntArray# ) import PrelBase ( Int(..) ) import PrelByteArr ( ByteArray(..), newIntArray ) import PrelArrExtra ( unsafeFreezeByteArray ) -import PrelNum ( fromInt ) import PrelIOBase ( IOException(..), IOErrorType( UnsupportedOperation ), unsafePerformIO, stToIO, ioException ) diff --git a/ghc/lib/std/Numeric.lhs b/ghc/lib/std/Numeric.lhs index 974c84b..167e8e5 100644 --- a/ghc/lib/std/Numeric.lhs +++ b/ghc/lib/std/Numeric.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: Numeric.lhs,v 1.11 2001/02/22 13:17:58 simonpj Exp $ +% $Id: Numeric.lhs,v 1.12 2001/02/22 16:48:24 qrczak Exp $ % % (c) The University of Glasgow, 1997-2000 % @@ -332,6 +332,6 @@ floatToDigits base x = else let bk = expt base (-k) in gen [] (r * bk) s (mUp * bk) (mDn * bk) - in (map toInt (reverse rds), k) + in (map fromIntegral (reverse rds), k) \end{code} #endif diff --git a/ghc/lib/std/PrelByteArr.lhs b/ghc/lib/std/PrelByteArr.lhs index 9662dbd..050a8ed 100644 --- a/ghc/lib/std/PrelByteArr.lhs +++ b/ghc/lib/std/PrelByteArr.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelByteArr.lhs,v 1.12 2001/02/22 13:17:58 simonpj Exp $ +% $Id: PrelByteArr.lhs,v 1.13 2001/02/22 16:48:24 qrczak Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -19,7 +19,6 @@ import PrelArr import PrelFloat import PrelST import PrelBase -import PrelNum ( fromInt ) \end{code} %********************************************************* diff --git a/ghc/lib/std/PrelCTypes.lhs b/ghc/lib/std/PrelCTypes.lhs index ea23afe..b2358fa 100644 --- a/ghc/lib/std/PrelCTypes.lhs +++ b/ghc/lib/std/PrelCTypes.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelCTypes.lhs,v 1.2 2001/02/22 13:17:58 simonpj Exp $ +% $Id: PrelCTypes.lhs,v 1.3 2001/02/22 16:48:24 qrczak Exp $ % % (c) The FFI task force, 2000 % @@ -24,7 +24,6 @@ module PrelCTypes \begin{code} import PrelBase ( unsafeCoerce# ) -import PrelReal ( Integral(toInt) ) import PrelBits ( Bits(..) ) import PrelInt ( Int8, Int16, Int32, Int64 ) import PrelWord ( Word8, Word16, Word32, Word64 ) diff --git a/ghc/lib/std/PrelCTypesISO.lhs b/ghc/lib/std/PrelCTypesISO.lhs index 6354864..dbcdcd1 100644 --- a/ghc/lib/std/PrelCTypesISO.lhs +++ b/ghc/lib/std/PrelCTypesISO.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelCTypesISO.lhs,v 1.4 2001/02/22 13:17:58 simonpj Exp $ +% $Id: PrelCTypesISO.lhs,v 1.5 2001/02/22 16:48:24 qrczak Exp $ % % (c) The FFI task force, 2000 % @@ -25,7 +25,6 @@ module PrelCTypesISO \begin{code} import PrelBase ( unsafeCoerce# ) -import PrelReal ( Integral(toInt) ) import PrelBits ( Bits(..) ) import PrelInt ( Int8, Int16, Int32, Int64 ) import PrelWord ( Word8, Word16, Word32, Word64 ) diff --git a/ghc/lib/std/PrelInt.lhs b/ghc/lib/std/PrelInt.lhs index 791a41c..19afb73 100644 --- a/ghc/lib/std/PrelInt.lhs +++ b/ghc/lib/std/PrelInt.lhs @@ -234,7 +234,6 @@ instance Integral Int8 where a@(I8# _) `quotRem` b@(I8# _) = (a `quotInt8` b, a `remInt8` b) toInteger i8 = toInteger (int8ToInt i8) - toInt i8 = int8ToInt i8 remInt8, quotInt8 :: Int8 -> Int8 -> Int8 @@ -257,7 +256,7 @@ instance Enum Int8 where | otherwise = i-1 toEnum x - | x >= toInt (minBound::Int8) && x <= toInt (maxBound::Int8) + | x >= fromIntegral (minBound::Int8) && x <= fromIntegral (maxBound::Int8) = intToInt8 x | otherwise = toEnumError "Int8" x (minBound::Int8,maxBound::Int8) @@ -378,7 +377,6 @@ instance Integral Int16 where a@(I16# _) `quotRem` b@(I16# _) = (a `quotInt16` b, a `remInt16` b) toInteger i16 = toInteger (int16ToInt i16) - toInt i16 = int16ToInt i16 remInt16, quotInt16 :: Int16 -> Int16 -> Int16 remInt16 (I16# x) (I16# y) = I16# (intToInt16# ((i16ToInt# x) `remInt#` (i16ToInt# y))) @@ -401,7 +399,7 @@ instance Enum Int16 where | otherwise = i-1 toEnum x - | x >= toInt (minBound::Int16) && x <= toInt (maxBound::Int16) + | x >= fromIntegral (minBound::Int16) && x <= fromIntegral (maxBound::Int16) = intToInt16 x | otherwise = toEnumError "Int16" x (minBound::Int16, maxBound::Int16) @@ -529,7 +527,6 @@ instance Integral Int32 where a@(I32# _) `quotRem` b@(I32# _) = (a `quotInt32` b, a `remInt32` b) toInteger i32 = toInteger (int32ToInt i32) - toInt i32 = int32ToInt i32 remInt32, quotInt32 :: Int32 -> Int32 -> Int32 remInt32 (I32# x) (I32# y) = I32# (intToInt32# ((i32ToInt# x) `remInt#` (i32ToInt# y))) @@ -554,7 +551,7 @@ instance Enum Int32 where toEnum x -- with Int having the same range as Int32, the following test -- shouldn't fail. However, having it here - | x >= toInt (minBound::Int32) && x <= toInt (maxBound::Int32) + | x >= fromIntegral (minBound::Int32) && x <= fromIntegral (maxBound::Int32) = intToInt32 x | otherwise = toEnumError "Int32" x (minBound::Int32, maxBound::Int32) @@ -663,7 +660,6 @@ instance Integral Int64 where a@(I64# _) `quotRem` b@(I64# _) = (a `quotInt64` b, a `remInt64` b) toInteger (I64# i#) = toInteger (I# i#) - toInt (I64# i#) = I# i# remInt64 (I64# x) (I64# y) = I64# (x `remInt#` y) quotInt64 (I64# x) (I64# y) = I64# (x `quotInt#` y) @@ -743,7 +739,6 @@ instance Integral Int64 where a@(I64# _) `quotRem` b@(I64# _) = (a `quotInt64` b, a `remInt64` b) toInteger i = int64ToInteger i - toInt i = int64ToInt i remInt64, quotInt64 :: Int64 -> Int64 -> Int64 remInt64 (I64# x) (I64# y) = I64# (x `remInt64#` y) diff --git a/ghc/lib/std/PrelNum.lhs b/ghc/lib/std/PrelNum.lhs index 33233a0..281ff76 100644 --- a/ghc/lib/std/PrelNum.lhs +++ b/ghc/lib/std/PrelNum.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: PrelNum.lhs,v 1.35 2001/02/22 13:17:59 simonpj Exp $ +% $Id: PrelNum.lhs,v 1.36 2001/02/22 16:48:24 qrczak Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -61,8 +61,8 @@ subtract :: (Num a) => a -> a -> a {-# INLINE subtract #-} subtract x y = y - x -ord_0 :: Num a => a -ord_0 = fromInt (ord '0') +ord_0 :: Int +ord_0 = ord '0' \end{code} diff --git a/ghc/lib/std/PrelReal.lhs b/ghc/lib/std/PrelReal.lhs index 9f309a9..acc4877 100644 --- a/ghc/lib/std/PrelReal.lhs +++ b/ghc/lib/std/PrelReal.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: PrelReal.lhs,v 1.8 2001/02/22 13:17:59 simonpj Exp $ +% $Id: PrelReal.lhs,v 1.9 2001/02/22 16:48:24 qrczak Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -89,7 +89,6 @@ class (Real a, Enum a) => Integral a where quot, rem, div, mod :: a -> a -> a quotRem, divMod :: a -> a -> (a,a) toInteger :: a -> Integer - toInt :: a -> Int -- partain: Glasgow extension n `quot` d = q where (q,_) = quotRem n d n `rem` d = r where (_,r) = quotRem n d @@ -98,6 +97,10 @@ class (Real a, Enum a) => Integral a where divMod n d = if signum r == negate (signum d) then (q-1, r+d) else qr where qr@(q,r) = quotRem n d +toInt :: Integral a => a -> Int +-- For backward compatibility +toInt i = fromInteger (toInteger i) + class (Num a) => Fractional a where (/) :: a -> a -> a recip :: a -> a @@ -161,7 +164,6 @@ instance Real Int where instance Integral Int where toInteger i = int2Integer i -- give back a full-blown Integer - toInt x = x -- Following chks for zero divisor are non-standard (WDP) a `quot` b = if b /= 0 @@ -191,7 +193,6 @@ instance Real Integer where instance Integral Integer where toInteger n = n - toInt n = integer2Int n n `quot` d = n `quotInteger` d n `rem` d = n `remInteger` d diff --git a/ghc/lib/std/PrelST.lhs b/ghc/lib/std/PrelST.lhs index 7e43b89..9efa299 100644 --- a/ghc/lib/std/PrelST.lhs +++ b/ghc/lib/std/PrelST.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: PrelST.lhs,v 1.19 2001/02/22 13:17:59 simonpj Exp $ +% $Id: PrelST.lhs,v 1.20 2001/02/22 16:48:24 qrczak Exp $ % % (c) The University of Glasgow, 1992-2000 % @@ -11,10 +11,9 @@ module PrelST where -import PrelNum -- To get fromInt etc, needed because of -fno-implicit-prelude -import PrelShow import PrelBase -import PrelNum () -- So that we get the .hi file for system imports +import PrelShow +import PrelNum default () \end{code} diff --git a/ghc/lib/std/PrelWord.lhs b/ghc/lib/std/PrelWord.lhs index e9110f4..5c23fba 100644 --- a/ghc/lib/std/PrelWord.lhs +++ b/ghc/lib/std/PrelWord.lhs @@ -280,7 +280,6 @@ instance Integral Word8 where divMod (W8# x) (W8# y) = (W8# (x `quotWord#` y), W8# (x `remWord#` y)) toInteger = toInteger . toInt - toInt = word8ToInt instance Ix Word8 where range (m,n) = [m..n] @@ -298,7 +297,7 @@ instance Enum Word8 where | otherwise = w-1 toEnum i@(I# i#) - | i >= toInt (minBound::Word8) && i <= toInt (maxBound::Word8) + | i >= fromIntegral (minBound::Word8) && i <= fromIntegral (maxBound::Word8) = W8# (intToWord8# i#) | otherwise = toEnumError "Word8" i (minBound::Word8,maxBound::Word8) @@ -441,8 +440,7 @@ instance Integral Word16 where quotRem (W16# x) (W16# y) = (W16# (x `quotWord#` y), W16# (x `remWord#` y)) divMod (W16# x) (W16# y) = (W16# (x `quotWord#` y), W16# (x `remWord#` y)) - toInteger = toInteger . toInt - toInt = word16ToInt + toInteger = toInteger . word16ToInt instance Ix Word16 where range (m,n) = [m..n] @@ -460,7 +458,7 @@ instance Enum Word16 where | otherwise = w-1 toEnum i@(I# i#) - | i >= toInt (minBound::Word16) && i <= toInt (maxBound::Word16) + | i >= fromIntegral (minBound::Word16) && i <= fromIntegral (maxBound::Word16) = W16# (intToWord16# i#) | otherwise = toEnumError "Word16" i (minBound::Word16,maxBound::Word16) @@ -602,7 +600,6 @@ instance Integral Word32 where divMod x y = quotRem x y toInteger = word32ToInteger - toInt = word32ToInt {-# INLINE quotWord32 #-} @@ -796,7 +793,6 @@ instance Integral Word64 where divMod (W64# x) (W64# y) = (W64# (x `quotWord#` y), W64# (x `remWord#` y)) toInteger (W64# x) = word2Integer# x - toInt x = word64ToInt x #else /* WORD_SIZE_IN_BYTES < 8 */ @@ -815,9 +811,7 @@ word64ToWord16 (W64# w#) = W16# ((word64ToWord# w#) `and#` (int2Word# 0xffff#)) word64ToInteger (W64# w#) = case word64ToInteger# w# of (# s#, p# #) -> J# s# p# -word64ToInt w = - case w `quotRem` 0x100000000 of - (_,l) -> toInt (word64ToWord32 l) +word64ToInt (W64# w#) = I# (word2Int# (word64ToWord# w#)) intToWord64# :: Int# -> Word64# intToWord64# i# = wordToWord64# (int2Word# i#) @@ -867,7 +861,6 @@ instance Integral Word64 where quotRem (W64# x) (W64# y) = (W64# (x `quotWord64#` y), W64# (x `remWord64#` y)) divMod (W64# x) (W64# y) = (W64# (x `quotWord64#` y), W64# (x `remWord64#` y)) toInteger w64 = word64ToInteger w64 - toInt x = word64ToInt x compareWord64# :: Word64# -> Word64# -> Ordering compareWord64# i# j# diff --git a/ghc/lib/std/Prelude.lhs b/ghc/lib/std/Prelude.lhs index 1e86072..0866192 100644 --- a/ghc/lib/std/Prelude.lhs +++ b/ghc/lib/std/Prelude.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: Prelude.lhs,v 1.23 2001/02/22 13:17:59 simonpj Exp $ +% $Id: Prelude.lhs,v 1.24 2001/02/22 16:48:24 qrczak Exp $ % % (c) The University of Glasgow, 1992-2000 % @@ -51,10 +51,9 @@ module Prelude ( Ord(..), Enum(..), Bounded(..), - Num((+), (-), (*), negate, abs, signum, fromInteger), + Num(..), Real(..), - Integral(quot, rem, div, mod, quotRem, divMod, toInteger), - -- The toInt method is exposed only by GlaExts + Integral(..), Fractional(..), Floating(..), RealFrac(..), diff --git a/ghc/lib/std/Random.lhs b/ghc/lib/std/Random.lhs index 920d986..7e60b47 100644 --- a/ghc/lib/std/Random.lhs +++ b/ghc/lib/std/Random.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: Random.lhs,v 1.22 2001/02/22 13:17:59 simonpj Exp $ +% $Id: Random.lhs,v 1.23 2001/02/22 16:48:24 qrczak Exp $ % % (c) The University of Glasgow, 1995-2000 % @@ -37,7 +37,6 @@ import PrelShow ( showSignedInt, showSpace ) import PrelRead ( readDec ) import PrelIOBase ( unsafePerformIO, stToIO ) import PrelArr ( STRef, newSTRef, readSTRef, writeSTRef ) -import PrelReal ( toInt ) import PrelFloat ( float2Double, double2Float ) import Time ( getClockTime, ClockTime(..) ) #else @@ -115,7 +114,7 @@ mkStdGen s createStdGen :: Integer -> StdGen createStdGen s | s < 0 = createStdGen (-s) - | otherwise = StdGen (toInt (s1+1)) (toInt (s2+1)) + | otherwise = StdGen (fromInteger (s1+1)) (fromInteger (s2+1)) where (q, s1) = s `divMod` 2147483562 s2 = q `mod` 2147483398 diff --git a/ghc/lib/std/cbits/CTypes.h b/ghc/lib/std/cbits/CTypes.h index df156cf..7a21335 100644 --- a/ghc/lib/std/cbits/CTypes.h +++ b/ghc/lib/std/cbits/CTypes.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: CTypes.h,v 1.3 2001/02/22 13:17:59 simonpj Exp $ + * $Id: CTypes.h,v 1.4 2001/02/22 16:48:24 qrczak Exp $ * * Dirty CPP hackery for CTypes/CTypesISO * @@ -90,8 +90,7 @@ instance Integral T where { \ (T i) `mod` (T j) = T (i `mod` j) ; \ (T i) `quotRem` (T j) = let (q,r) = i `quotRem` j in (T q, T r) ; \ (T i) `divMod` (T j) = let (d,m) = i `divMod` j in (T d, T m) ; \ - toInteger (T i) = toInteger i ; \ - toInt (T i) = toInt i } + toInteger (T i) = toInteger i } #define INSTANCE_BITS(T) \ instance Bits T where { \ @@ -260,8 +259,7 @@ instance Integral T where { \ mod = unsafeCoerce# (mod:: B -> B -> B); \ quotRem = unsafeCoerce# (quotRem:: B -> B -> (B,B)); \ divMod = unsafeCoerce# (divMod:: B -> B -> (B,B)); \ - toInteger = unsafeCoerce# (toInteger:: B -> Integer); \ - toInt = unsafeCoerce# (toInt:: B -> Int); } + toInteger = unsafeCoerce# (toInteger:: B -> Integer); } #define INSTANCE_BITS(T,B) \ instance Bits T where { \ -- 1.7.10.4