(* Flowcaml examples used in Lecture 7 *) flow !l < !h;; let l : (!l bool, 'a) ref = ref false;; let h : (!h bool, 'a) ref = ref false;; let count :(!alice int, 'a) ref = ref 0;; h := !l;; (* the assignment below is rejected by type checking *) l := !h;; (* these functions model the four assignment statements discussed in class *) let a1 x y = x := !y;; let a2 x y = x := if !y then true else false;; let a3 x y = if !y then x:= true else x := false;; let a4 x y = x := false; if !y then x := true ;; (* apply a1 -- a4 to l and h to get positive and negative examples *) (* some functions with effects *) let incr () = count := !count +1;; let toggle x = x:= not !x;; (* a definition of while *) let rec wh guard comm () = if (guard ()) then (comm (); wh guard comm ()) else ();; (* K combinator: generates constant functions *) let k x y = x;; (* a program that quickly halts *) wh (k false) incr;; (* a program that runs forever *) wh (k true) incr;;