[commit: ghc] master: Weaken constraints on Data.Complex functions (7b04d35)
git at git.haskell.org
git at git.haskell.org
Sat Apr 19 12:27:43 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/7b04d35a87f1ee2904579a916ef1a6b0aa6fc7b8/ghc
>---------------------------------------------------------------
commit 7b04d35a87f1ee2904579a916ef1a6b0aa6fc7b8
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Sat Apr 19 13:56:36 2014 +0200
Weaken constraints on Data.Complex functions
The RealFloat data type context was dropped from Data.Complex some time
ago (see ea280135dd888ac41d8804a9e37e358180cf13ac). 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.html
Signed-off-by: Herbert Valerio Riedel <hvr at gnu.org>
>---------------------------------------------------------------
7b04d35a87f1ee2904579a916ef1a6b0aa6fc7b8
libraries/base/Data/Complex.hs | 10 +++++-----
libraries/base/changelog.md | 2 ++
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/libraries/base/Data/Complex.hs b/libraries/base/Data/Complex.hs
index 190c598..b03848b 100644
--- a/libraries/base/Data/Complex.hs
+++ b/libraries/base/Data/Complex.hs
@@ -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
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 3011fdf..a72e4e6 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -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
More information about the ghc-commits
mailing list