(* Code of Figure 9.2, page 365 from Kenneth C. Louden, Programming Languages Principles and Practice 2nd Edition Copyright (C) Brooks-Cole/ITP, 2003 (Test code from page 366 added, too.) *) abstype Complex = C of real * real with fun makecomplex (x,y) = C (x,y); fun realpart (C (r,i)) = r; fun imaginarypart (C (r,i)) = i; fun +: ( C (r1,i1), C (r2,i2) ) = C (r1+r2, i1+i2); infix 6 +: ; (* other operations *) end; val z = makecomplex (1.0,2.0); val w = makecomplex (2.0,~1.0); (* ~ is negation *) val x = z +: w; realpart x; imaginarypart x;