我们有下一个dayatype:
datatype complex = Rec of real * real | Polar of real * real;
和两个功能:
- val real =
fn (Rec(x,y) ) => x
| (Polar(r,a)) => r * Math.cos(a);
val real = fn : complex -> real
- val imaginary =
fn (Rec(x,y) ) => y
| (Polar(r,a)) => r * Math.sin(a);
val imaginary = fn : complex -> real
现在,这本书定义了另一个函数:
- val add_complex =
fn (Rec(x, y), Rec(x', y')) => ( Rec( x + x', y + y') )
| (Rec(x,y), z) => ( Rec( x + real(z), y + imaginary(z) ) )
| (z, Rec(x, y)) => ( Rec( real(z) + x, imaginary(z) + y) )
| (z,z') => (Rec( real(z) + real(z'), imaginary(z) + imaginary(z') ) );
val add_complex = fn : complex * complex -> complex
我不明白z
函数中的内容是什么add_complex
。
它是 Polar 吗(意思是,我可以写 Z=polar(a,b)?如果是,那么编译器是如何知道的?意思是 - 它是否得到 az,并将其解析为极坐标变量?
如果它不是极地,那它会是什么?