Commits

Aleksey Khudyakov committed 0a6abe3

Use Real type class instead of ToDouble

Oops :-/

  • Participants
  • Parent commits 106ccc2

Comments (0)

Files changed (1)

File Data/Monoid/Statistics/Numeric.hs

     -- * Maximum and minimum
   , Max(..)
   , Min(..)
-    -- * Conversion to Double
-  , ConvertibleToDouble(..)
   ) where
 
 import Data.Int     (Int8, Int16, Int32, Int64)
   {-# INLINE mempty  #-}
   {-# INLINE mappend #-}
 
-instance ConvertibleToDouble a => StatMonoid Mean a where
-  pappend !x !(Mean n m) = Mean n' (m + (toDouble x - m) / fromIntegral n') where n' = n+1
+instance Real a => StatMonoid Mean a where
+  pappend !x !(Mean n m) = Mean n' (m + (realToFrac x - m) / fromIntegral n') where n' = n+1
   {-# INLINE pappend #-}
 
 instance CalcCount Mean where
   {-# INLINE mempty #-}
   {-# INLINE mappend #-}
 
-instance ConvertibleToDouble a => StatMonoid Variance a where
+instance Real a => StatMonoid Variance a where
   -- Can be implemented directly as in Welford-Knuth algorithm.
-  pappend !x !s = s `mappend` (Variance 1 (toDouble x) 0)
+  pappend !x !s = s `mappend` (Variance 1 (realToFrac x) 0)
   {-# INLINE pappend #-}
 
 instance CalcCount Variance where
 
 
 ----------------------------------------------------------------
--- Conversion to Double
+-- Helpers
 ----------------------------------------------------------------
-
--- | Data type which could be convered to Double
-class ConvertibleToDouble a where
-  toDouble :: a -> Double
-  
--- Floating point
-instance ConvertibleToDouble Double where
-  toDouble = id
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Float where
-  toDouble = float2Double
-  {-# INLINE toDouble #-}
--- Basic integral types
-instance ConvertibleToDouble Integer where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Int where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Word where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
--- Integral types with fixed size
-instance ConvertibleToDouble Int8 where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Int16 where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Int32 where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Int64 where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Word8 where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Word16 where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Word32 where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-instance ConvertibleToDouble Word64 where
-  toDouble = fromIntegral
-  {-# INLINE toDouble #-}
-
  
 sqr :: Double -> Double
 sqr x = x * x