Execution Result

# val sqrt = Real.Math.sqrt ;
val sqrt = fn : Real.Math.real -> Real.Math.real
# val P1 = fn M => #CPoint M {x=10.0, y = 10.0};
val P1 = fn : ['a#{CPoint:{x:real , y:real} -> 'b},'b.'a -> 'b]
# val P2 = fn M => #PPoint M {r=14.1421356, theta = 45.0 };
val P2 = fn : ['a#{PPoint:{r:real , theta:real}  ,'b.'a -> 'b]
# val myPointList = [P1, P2];
val myPointList = [fn,fn] : ['a,'b#{CPoint:{x:real , y:real} -> 'a, PPoint: {r:real , theta:real} -> 'a}.
 ('b -> 'a) list]
# val distance =
>  {CPoint = fn {x,y} => sqrt (x *x + y* y),
>   PPoint = fn {r, theta} => r};
val distance = { CPoint = fn, PPoint = fn } : {
  CPoint:{x:real , y:real} -> Real.Math.real ,
  PPoint:['a,'b.{r:'b , theta:'a} -> 'b]
}
# val angle =
>  {CPoint = fn {x,y} => (Math.atan (x / y) / Math.pi) * 180.0,
>   PPoint = fn {r, theta} => theta};
val angle = { CPoint = fn, PPoint = fn } : {CPoint:{x:real , y:real} ->  real , PPoint:['a,'b.{r:'b , theta:'a} -> 'a]}
# P1 distance ;
val it = 14.1421 : real
# P2 distance ;
val it = 14.1421 : real
# P1 angle ;
val it = 45 : real
# P2 angle ;
val it = 45 : real
# fun iterator L f = map (fn x => x f) L;
val iterator = fn : ['a,'b.('a -> 'b) List.list -> 'a -> 'b List.list]
# val myPointLstIter = fn x => iterator myPointList x;
val myPointLstIter = fn : ['a#{CPoint:{x:real , y:real} -> 'b, PPoint: {r:real , theta:real} -> 'b},'b.
 'a -> 'b List.list]
# myPointLstIter distance;
val it = [14.1421,14.1421] : real List.list
# myPointLstIter angle;
val it = [45,45] : real List.list
#
Last modified:2006/03/06 02:12:09
Keyword(s):
References:[Polymorphic variant]