structure Argand : ComplexSig = struct type complex = real * real; fun r X (a, m) : complex = (a, r*m) fun (a, m) ** (a', m'): complex = (a + a', m * m') and (a, m) // (a', m'): complex = (a - a', m / m') and ~~(a, m) : complex = (a, ~m) and (a,b) == (c,d) = (a=c) andalso (b=d) val pi = 4.0 * arctan 1.0; fun descartes {real=r, imag=i} = let val argument = if r = 0.0 then if i < 0.0 then ~pi/2.0 else pi/2.0 else arctan(i/r) val modulus = sqrt(r*r + i*i) in (argument, modulus) end and argand {modulus, argument} = (argument, modulus) and realpart (a, m) = m * cos a and imagpart (a, m) = m * sin a and modulus (a, m) = m and argument (a, m) = a fun x ++ y = let val r = realpart x + realpart y and i = imagpart x + imagpart y in descartes{real = r, imag = i} end fun x -- y = x ++ (~~ y) end;