@@ -63,15 +63,16 @@ conjugate (r:+i) = (r :+ (0-i))
63implementation Functor Complex where
63implementation Functor Complex where
64 map f (r :+ i) = f r :+ f i
64 map f (r :+ i) = f r :+ f i
66−-- We can't do "implementation Num a => Num (Complex a)" because
66+-- We can do "implementation Neg a => Num (Complex a)" because
67−-- we need "abs" which needs "magnitude" which needs "sqrt" which needs Double
67+-- we don't need "abs", only (-)
68−implementation Num (Complex Double) where
68+implementation Neg a => Num (Complex a) where
69 (+) (a:+b) (c:+d) = ((a+c):+(b+d))
69 (+) (a:+b) (c:+d) = ((a+c):+(b+d))
70 (*) (a:+b) (c:+d) = ((a*c-b*d):+(b*c+a*d))
70 (*) (a:+b) (c:+d) = ((a*c-b*d):+(b*c+a*d))
71 fromInteger x = (fromInteger x:+0)
71 fromInteger x = (fromInteger x:+0)
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
73implementation Neg (Complex Double) where
75implementation Neg (Complex Double) where
74 negate = map negate
76 negate = map negate
75 (-) (a:+b) (c:+d) = ((a-c):+(b-d))
77 (-) (a:+b) (c:+d) = ((a-c):+(b-d))
76 abs (a:+b) = (magnitude (a:+b):+0)
78 abs (a:+b) = (magnitude (a:+b):+0)