Commit 7b04d35a authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺

Weaken constraints on Data.Complex functions

The RealFloat data type context was dropped from Data.Complex some time
ago (see ea280135). However, the rest of
the API in that module was left as-is even though many of the accessors
in that module would work with much more general types now.

This change simplifies the signatures of the functions above, which in
the current API all unnecessarily take a RealFloat constraint that they
don't use (and which may cause to pass around superflous type-class
dictionaries):

    realPart  :: Complex a -> a
    imagPart  :: Complex a -> a
    conjugate :: Num a => Complex a -> Complex a
    mkPolar   :: Floating a => a -> a -> Complex a
    cis       :: Floating a => a -> Complex a

This was originally proposed by Edward Kmett in

  http://www.haskell.org/pipermail/libraries/2014-March/022358.htmlSigned-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
parent dc2b8ae2
......@@ -58,27 +58,27 @@ data Complex a
-- Functions over Complex
-- | Extracts the real part of a complex number.
realPart :: (RealFloat a) => Complex a -> a
realPart :: Complex a -> a
realPart (x :+ _) = x
-- | Extracts the imaginary part of a complex number.
imagPart :: (RealFloat a) => Complex a -> a
imagPart :: Complex a -> a
imagPart (_ :+ y) = y
-- | The conjugate of a complex number.
{-# SPECIALISE conjugate :: Complex Double -> Complex Double #-}
conjugate :: (RealFloat a) => Complex a -> Complex a
conjugate :: Num a => Complex a -> Complex a
conjugate (x:+y) = x :+ (-y)
-- | Form a complex number from polar components of magnitude and phase.
{-# SPECIALISE mkPolar :: Double -> Double -> Complex Double #-}
mkPolar :: (RealFloat a) => a -> a -> Complex a
mkPolar :: Floating a => a -> a -> Complex a
mkPolar r theta = r * cos theta :+ r * sin theta
-- | @'cis' t@ is a complex value with magnitude @1@
-- and phase @t@ (modulo @2*'pi'@).
{-# SPECIALISE cis :: Double -> Complex Double #-}
cis :: (RealFloat a) => a -> Complex a
cis :: Floating a => a -> Complex a
cis theta = cos theta :+ sin theta
-- | The function 'polar' takes a complex number and
......
......@@ -8,6 +8,8 @@
* Add `Data.List.sortOn` sorting function
* Weaken RealFloat constraints on some `Data.Complex` functions
## 4.7.0.0 *Apr 2014*
* Bundled with GHC 7.8.1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment