on master help sign in
Fixed the Num instance for Complex

Due to a historical artifact, the `Num` implementation for `Complex` only covered `Double`, because `abs` used to be in `Num` (like in Haskell). Since these implementations are now split, we can implent Num with only `Neg a` instead of Double. As soon as `abs` moves out of `Neg` (issue #3500), we can also loosen the requirment for the `Neg` implementation to only need `Neg a`: ```idris implementation Neg a => Neg (Complex a) where negate = map negate (-) (a:+b) (c:+d) = ((a-c):+(b-d)) ```

commit02159a32a926dcaa6657138c21760b4931e44de0 authorSynthetica9 <patrickhilhorst97@gmail.com> dateFri 9 Dec 2016, 20:08 (10 years ago) parent280810b
1 file changed+5−4
libs/base/Data/Complex.idr+5−4
libs/base/Data/Complex.idr+5−4
@@ -63,15 +63,16 @@ conjugate (r:+i) = (r :+ (0-i))
6363implementation Functor Complex where
6464 map f (r :+ i) = f r :+ f i
6565
66−-- We can't do "implementation Num a => Num (Complex a)" because
67−-- we need "abs" which needs "magnitude" which needs "sqrt" which needs Double
68−implementation Num (Complex Double) where
66+-- We can do "implementation Neg a => Num (Complex a)" because
67+-- we don't need "abs", only (-)
68+implementation Neg a => Num (Complex a) where
6969 (+) (a:+b) (c:+d) = ((a+c):+(b+d))
7070 (*) (a:+b) (c:+d) = ((a*c-b*d):+(b*c+a*d))
7171 fromInteger x = (fromInteger x:+0)
7272
73+-- We can't do "implementation Neg a => Num (Complex a)" because
74+-- we need "abs" which needs "magnitude" which needs "sqrt" which needs Double
7375implementation Neg (Complex Double) where
7476 negate = map negate
7577 (-) (a:+b) (c:+d) = ((a-c):+(b-d))
7678 abs (a:+b) = (magnitude (a:+b):+0)
77−