Make two type defaults explicit
authorsimonpj@microsoft.com <unknown>
Fri, 29 May 2009 08:35:49 +0000 (08:35 +0000)
committersimonpj@microsoft.com <unknown>
Fri, 29 May 2009 08:35:49 +0000 (08:35 +0000)
Now that -Werror rejects programs that use silent type-class defaulting,
we must commit in the source code.

I've used Double in CPUTime, which is the same as was picked automatically
before, but I expect Float would be ok.

   realToInteger :: Real a => a -> Integer
   realToInteger ct = round (realToFrac ct :: Double)

In GHC.Float I used Float (rather that than the auto-picked Double)
because I'm pretty certain it has enough precision.

-- f :: Integer, log :: Float -> Float,
        --               ceiling :: Float -> Int
        ceiling ((log (fromInteger (f+1) :: Float) +

GHC/Float.lhs
System/CPUTime.hsc

index d68119c..3059db9 100644 (file)
@@ -625,7 +625,9 @@ floatToDigits base x =
         -- Haskell promises that p-1 <= logBase b f < p.
         (p - 1 + e0) * 3 `div` 10
      else
-        ceiling ((log (fromInteger (f+1)) +
+       -- f :: Integer, log :: Float -> Float, 
+        --               ceiling :: Float -> Int
+        ceiling ((log (fromInteger (f+1) :: Float) +
                  fromIntegral e * log (fromInteger b)) /
                    log (fromInteger base))
 --WAS:            fromInt e * log (fromInteger b))
index b5d86d8..307b2a2 100644 (file)
@@ -37,6 +37,11 @@ import Foreign.C
 #include "HsBase.h"
 #endif
 
+realToInteger :: Real a => a -> Integer
+realToInteger ct = round (realToFrac ct :: Double)
+  -- CTime, CClock, CUShort etc are in Real but not Fractional, 
+  -- so we must convert to Double before we can round it
+
 #ifdef __GLASGOW_HASKELL__
 -- -----------------------------------------------------------------------------
 -- |Computation 'getCPUTime' returns the number of picoseconds CPU time
@@ -64,7 +69,6 @@ getCPUTime = do
     u_usec <- (#peek struct timeval,tv_usec) ru_utime :: IO CTime
     s_sec  <- (#peek struct timeval,tv_sec)  ru_stime :: IO CTime
     s_usec <- (#peek struct timeval,tv_usec) ru_stime :: IO CTime
-    let realToInteger = round . realToFrac :: Real a => a -> Integer
     return ((realToInteger u_sec * 1000000 + realToInteger u_usec + 
              realToInteger s_sec * 1000000 + realToInteger s_usec) 
                 * 1000000)
@@ -77,7 +81,6 @@ foreign import ccall unsafe getrusage :: CInt -> Ptr CRUsage -> IO CInt
     times p_tms
     u_ticks  <- (#peek struct tms,tms_utime) p_tms :: IO CClock
     s_ticks  <- (#peek struct tms,tms_stime) p_tms :: IO CClock
-    let realToInteger = round . realToFrac :: Real a => a -> Integer
     return (( (realToInteger u_ticks + realToInteger s_ticks) * 1000000000000) 
                         `div` fromIntegral clockTicks)