# HG changeset patch # User Alexey Khudyakov # Date 1297861194 -10800 # Node ID 0a6abe39403d64010a4692925763003f8e01aca1 # Parent 106ccc219f0705a4fe92759fa845fabc55b2f866 Use Real type class instead of ToDouble Oops :-/ diff --git a/Data/Monoid/Statistics/Numeric.hs b/Data/Monoid/Statistics/Numeric.hs --- a/Data/Monoid/Statistics/Numeric.hs +++ b/Data/Monoid/Statistics/Numeric.hs @@ -20,8 +20,6 @@ -- * Maximum and minimum , Max(..) , Min(..) - -- * Conversion to Double - , ConvertibleToDouble(..) ) where import Data.Int (Int8, Int16, Int32, Int64) @@ -84,8 +82,8 @@ {-# 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 @@ -131,9 +129,9 @@ {-# 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 @@ -223,56 +221,8 @@ ---------------------------------------------------------------- --- 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