Script started on Wed Nov 13 16:26:40 1991 warning: could not update utmp entry simpson-04% sml Standard ML of New Jersey, Version 0.66, 15 September 1990 val it = () : unit - val p = ref 5 and q = ref 2; val p = ref 5 : int ref val q = ref 2 : int ref - !p; val it = 5 : int - !q; val it = 2 : int - x = (p,q); val x = (ref 5,ref 2) : int ref * int ref - p := 99; val it = () : unit - !p; val it = 99 : int - x; val it = (ref 99,ref 2) : int ref * int ref - (p := !p + 1; q := !q + 1); val it = () : unit - x; val it = (ref 100,ref 3) : int ref * int ref - val l = [p,q]; val l = [ref 100,ref 3] : int ref list - q:= 1234; val it = () : unit - x; val it = (ref 100,ref 1234) : int ref * int ref - l; val it = [ref 100,ref 1234] : int ref list - hd l; val it = ref 100 : int ref - !(hd l); val it = 100 : int - p = q; val it = false : bool - val pp = p; val pp = ref 100 : int ref - pp = p; val it = true : bool - q := 100; val it = () : unit - p = q; val it = false : bool - !p = !q; val it = true : bool - (* That is p does not equal q. They are different = however, they when dereference they are the same *) - (* cyclic data structures ??? *) - val f' = ref(fn k => k+1); val f' = ref fn : (int -> int) ref - !f' 3; val it = 4 : int - fun f n = if n = 0 then 1 else n * !f'(n-1); val f = fn : int -> int - f 3; val it = 9 : int - f 1; val it = 1 : int - f 2; val it = 4 : int - (* looks like f x = x*x *) - f' := f; val it = () : unit - (* CLOSE THE KNOT *) - f 1; val it = 1 : int - f 2; val it = 2 : int - f 3; val it = 6 : int - f 4; val it = 24 : int - (* f x is now x! *) - (* vectors ???? *) - use "vectors"; [opening vectors] [closing vectors] val it = () : unit - val x = make_vector 5 (ref 0); val x = Node (Node (Node #,ref #,Lf),ref 0,Node (Node #,ref #,Lf)) : int ref tree - (get x 1) := 1; val it = () : unit - get x 1; val it = ref 1 : int ref - get x 2; val it = ref 1 : int ref - get x 3; val it = ref 1 : int ref - get x 4; val it = ref 1 : int ref - get x 5; val it = ref 1 : int ref - (get x 5) := 6; val it = () : unit - get x 1; val it = ref 6 : int ref - (* Woops!!!*) - (* list ref, polymorphic ???*) - val x = ref []; std_in:19.5-19.14 Error: nongeneric weak type variable x : '0Z list ref - val x = ref [1]; val x = ref [1] : int list ref - x := [1,2,3]; val it = () : unit - x := ["a"]; std_in:3.1-3.10 Error: operator and operand don't agree (tycon mismatch) operator domain: int list ref * int list operand: int list ref * string list in expression: := (x,"a" :: nil) - !x; val it = [1,2,3] : int list - 3 :: !x; val it = [3,1,2,3] : int list - (* The real thing ? *) - datatype 'a ring = empty|Node of 'a * 'a ring ref; datatype 'a ring con Node : 'a * 'a ring ref -> 'a ring con empty : 'a ring - empty; val it = empty : 'a ring - val n1 = Node(1,(ref empty)); val n1 = Node (1,ref empty) : int ring - val n2 = Node(2,(ref n1)); val n2 = Node (2,ref (Node (#,#))) : int ring - val (Node(a,t)) = n1; std_in:3.5-3.20 Warning: binding not exhaustive Node (a,t) = ... val a = 1 : int val t = ref empty : int ring ref - t := n2; val it = () : unit - (* CLOSE THE KNOT *) - n1; val it = Node (1,ref (Node (#,#))) : int ring - n2; val it = Node (2,ref (Node (#,#))) : int ring - val (Node(a,b)) = n1; std_in:8.5-8.20 Warning: binding not exhaustive Node (a,b) = ... val a = 1 : int val b = ref (Node (2,ref (Node #))) : int ring ref - val (Node(c,d)) = !b; std_in:1.5-1.20 Warning: binding not exhaustive Node (c,d) = ... val c = 2 : int val d = ref (Node (1,ref (Node #))) : int ring ref simpson-04% script done on Wed Nov 13 16:58:19 1991