blob: b4942bb9c2b908ec6c3d98380558583e6c8e1fd1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
% From Haskell report PreludeComlex.hs
\begin{verbatim}
instance (RealFloat a) => Num (Complex a) where
(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')
negate (x:+y) = negate x :+ negate y
abs z = magnitude z :+ 0
signum 0 = 0
signum z@(x:+y) = x/r :+ y/r where r = magnitude z
fromInteger n = fromInteger n :+ 0
\end{verbatim}
|