Add a few SPECIALISE/INLINE pragmas.
\begin{code}
instance (RealFloat a) => Num (Complex a) where
+ {-# SPECIALISE instance Num (Complex Float) #-}
+ {-# SPECIALISE instance Num (Complex Double) #-}
(x:+y) + (x':+y') = (x+x') :+ (y+y')
(x:+y) - (x':+y') = (x-x') :+ (y-y')
(x:+y) * (x':+y') = (x*x'-y*y') :+ (x*y'+y*x')
fromInteger n = fromInteger n :+ 0
instance (RealFloat a) => Fractional (Complex a) where
+ {-# SPECIALISE instance Fractional (Complex Float) #-}
+ {-# SPECIALISE instance Fractional (Complex Double) #-}
(x:+y) / (x':+y') = (x*x''+y*y'') / d :+ (y*x''-x*y'') / d
where x'' = scaleFloat k x'
y'' = scaleFloat k y'
fromRational a = fromRational a :+ 0
instance (RealFloat a) => Floating (Complex a) where
+ {-# SPECIALISE instance Floating (Complex Float) #-}
+ {-# SPECIALISE instance Floating (Complex Double) #-}
pi = pi :+ 0
exp (x:+y) = expx * cos y :+ expx * sin y
where expx = exp x
signum x | x == 0.0 = 0
| x > 0.0 = 1
| otherwise = negate 1
+
+ {-# INLINE fromInteger #-}
fromInteger n = encodeFloat n 0
+ -- It's important that encodeFloat inlines here, and that
+ -- fromInteger in turn inlines,
+ -- so that if fromInteger is applied to an (S# i) the right thing happens
+
+ {-# INLINE fromInt #-}
fromInt i = int2Float i
instance Real Float where
foreign import ccall "__int_encodeFloat" unsafe
int_encodeFloat# :: Int# -> Int -> Float
+
foreign import ccall "isFloatNaN" unsafe isFloatNaN :: Float -> Int
foreign import ccall "isFloatInfinite" unsafe isFloatInfinite :: Float -> Int
foreign import ccall "isFloatDenormalized" unsafe isFloatDenormalized :: Float -> Int
signum x | x == 0.0 = 0
| x > 0.0 = 1
| otherwise = negate 1
+
+ {-# INLINE fromInteger #-}
+ -- See comments with Num Float
fromInteger n = encodeFloat n 0
fromInt (I# n#) = case (int2Double# n#) of { d# -> D# d# }
\begin{code}
-- sum and product compute the sum or product of a finite list of numbers.
{-# SPECIALISE sum :: [Int] -> Int #-}
+{-# SPECIALISE sum :: [Integer] -> Integer #-}
{-# SPECIALISE product :: [Int] -> Int #-}
+{-# SPECIALISE product :: [Integer] -> Integer #-}
sum, product :: (Num a) => [a] -> a
#ifdef USE_REPORT_PRELUDE
sum = foldl (+) 0