1 / 0;; List.hd [] ;; exception Our_int_exception of int;; Our_int_exception 5;; Failure "hey";; raise (Failure "hey");; List.hd;; let hd = fun l -> match l with \n [] -> raise (Failure "our hd failed for []")\n | a::ll -> a;; hd [1;2;3;4];; hd [];; let hd = fun l -> match l with \n [] -> raise (Our_int_exception 3)\n | a::ll -> a;; hd [];; try 1 / 0 with\n Division_by_zero -> 0\n | Our_int_exception n -> n\n | Failure s -> -1;; 1/0;; try hd [] with Division_by_zero -> 0 | Failure s -> 1;; try hd [] with Division_by_zero -> 0 | Failure s -> 1 | Our_int_exception n -> n;; ();; 5;; print_string("a\\n");; print_string("a\\n"); 5;; 5;; 6; 5;; [|0;1;2;3|];; [|0;1;2;3|].(2);; [|0;10;20;30|].(2);; [|0;1;2;3|].(2) <- 200;; let a = [|0;1;2;3|].(2) <- 200;; a;; let a = [|0;1;2;3|];; let a.(2) <- 200;; a.(2) <- 200;; let a = [|0;1;2;3|];; a.(2) <- 200;; a;; let f v i j = let temp = v.(i); v.(i) <- v.(j); v.(j) <- temp;; let f v i j = (let temp = v.(i); v.(i) <- v.(j); v.(j) <- temp);; let f v i j = let temp = v.(i) in (v.(i) <- v.(j); v.(j) <- temp);; let swap v i j = let temp = v.(i) in (v.(i) <- v.(j); v.(j) <- temp);; swap [|0;1;2;3|] 2 3;; let a = [|0;1;2;3|];; swap a 2 3;; a;; type mpoint = {mutable x:float; mutable y: float};; let move = fun ((dx, dy), p) -> p.x <- p.x +. dx; p.y <- p.y +. dy;; let p = {x=1.; y=2.};; move ((1., 1.), p);; p;; let mp1 = {x = 1.; y=2.};; let mp2 = {x = 1.; y=2.};; mp1=mp2;; mp1==mp2;; mp1;; mp2;; let mp3 = mp1;; move ((10., 10.) mp1);; move ((10., 10.), mp1);; mp1;; mp3;; mp2;; let mp2 = {x = 1.; y=2.};; let x=5;; let y=5;; x==y;; mp3=mp1;; mp1=mp2;; let mp1 = {x = 1.; y=2.};; let mp2 = {x = 1.; y=2.};; mp1;; mp2;; mp1=mp2;; mp1==mp2;; ref;; let c = ref 0;; c;; !c;; let l = [ref 1; ref 2; ref 3];; List.hd(1);; List.hd(l);; !List.hd(l);; !(List.hd(l));; c;; c:=5;; c;; !c;; let c = ref 0;; c := 5;; c;; let gensym = let counter = ref 0 in (fun () -> counter := !counter + 1; "sym"^(string_of_int !counter));; let gensym = let counter = ref 0 in fun () -> (counter := !counter + 1; "sym"^(string_of_int !counter));; gensym();; let gensym = let counter = ref 0 in fun () -> (counter := !counter + 1; "sym"^(string_of_int !counter));; gensym();; let gensym = let counter = ref 0 in fun () -> (counter := !counter + 1; "sym"^(string_of_int !counter));; module type LIST_STACK = sig\n (** [Empty] is raised when an operation cannot be applied\n to an empty stack. *)\n exception Empty\n\n (** [empty] is the empty stack. *)\n val empty : 'a list\n\n (** [is_empty s] is whether [s] is empty. *)\n val is_empty : 'a list -> bool\n\n (** [push x s] pushes [x] onto the top of [s]. *)\n val push : 'a -> 'a list -> 'a list\n\n (** [peek s] is the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val peek : 'a list -> 'a\n\n (** [pop s] is all but the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val pop : 'a list -> 'a list\nend;; module ListStack : LIST_STACK = struct\n let empty = []\n\n let is_empty = function [] -> true | _ -> false\n\n let push x s = x :: s\n\n exception Empty\n\n let peek = function\n | [] -> raise Empty\n | x :: _ -> x\n\n let pop = function\n | [] -> raise Empty\n | _ :: s -> s\nend;; ListStack.push 2 (ListStack.push 1 ListStack.empty);; ListStack.(push 2 (push 1 empty));; module type LIST_STACK = sig\n (** [Empty] is raised when an operation cannot be applied\n to an empty stack. *)\n exception Empty\n\n (** [empty] is the empty stack. *)\n val empty : 'a list\n\n (** [is_empty s] is whether [s] is empty. *)\n val is_empty : 'a list -> bool\n\n (** [push x s] pushes [x] onto the top of [s]. *)\n val push : 'a -> 'a list -> 'a list\n\n (** [peek s] is the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val peek : 'a list -> 'a\n\n (** [pop s] is all but the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val pop : 'a list -> 'a list\nend;; module type LIST_STACK = sig\n (** [Empty] is raised when an operation cannot be applied\n to an empty stack. *)\n\n (** [empty] is the empty stack. *)\n val empty : 'a list\n\n (** [is_empty s] is whether [s] is empty. *)\n val is_empty : 'a list -> bool\n\n (** [push x s] pushes [x] onto the top of [s]. *)\n val push : 'a -> 'a list -> 'a list\n\n (** [peek s] is the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val peek : 'a list -> 'a\n\n (** [pop s] is all but the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val pop : 'a list -> 'a list\nend;; module ListStack : LIST_STACK = struct\n let empty = []\n\n let is_empty = function [] -> true | _ -> false\n\n let push x s = x :: s\n\n exception Empty\n\n let peek = function\n | [] -> raise Empty\n | x :: _ -> x\n\n let pop = function\n | [] -> raise Empty\n | _ :: s -> s\nend;; ListStack.pop [];; try ListStack.pop [] with ListStack.Empty -> [];; module type LIST_STACK = sig\n (** [Empty] is raised when an operation cannot be applied\n to an empty stack. *)\n exception Empty\n\n (** [empty] is the empty stack. *)\n val empty : 'a list\n\n (** [is_empty s] is whether [s] is empty. *)\n val is_empty : 'a list -> bool\n\n (** [push x s] pushes [x] onto the top of [s]. *)\n val push : 'a -> 'a list -> 'a list\n\n (** [peek s] is the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val peek : 'a list -> 'a\n\n (** [pop s] is all but the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val pop : 'a list -> 'a list\nend;; module ListStack : LIST_STACK = struct\n let empty = []\n\n let is_empty = function [] -> true | _ -> false\n\n let push x s = x :: s\n\n exception Empty\n\n let peek = function\n | [] -> raise Empty\n | x :: _ -> x\n\n let pop = function\n | [] -> raise Empty\n | _ :: s -> s\nend;; try ListStack.pop [] with ListStack.Empty -> [];; module type LIST_STACK = sig\n (** [Empty] is raised when an operation cannot be applied\n to an empty stack. *)\n exception Empty\n\n (** [empty] is the empty stack. *)\n val empty : 'a list\n\n (** [is_empty s] is whether [s] is empty. *)\n val is_empty : 'a list -> bool\n\n (** [push x s] pushes [x] onto the top of [s]. *)\n val push : 'a -> 'a list -> 'a list\n\n (** [peek s] is the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val peek : 'a list -> 'a\nend;; module type LIST_STACK = sig\n (** [Empty] is raised when an operation cannot be applied\n to an empty stack. *)\n exception Empty\n\n (** [empty] is the empty stack. *)\n val empty : 'a list\n\n (** [is_empty s] is whether [s] is empty. *)\n val is_empty : 'a list -> bool\n\n (** [push x s] pushes [x] onto the top of [s]. *)\n val push : 'a -> 'a list -> 'a list\n\n (** [peek s] is the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val peek : 'a list -> 'a\n\n (** [pop s] is all but the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val pop : 'a list -> 'a list\nend;; module ListStack : LIST_STACK = struct\n let empty = []\n\n let is_empty = function [] -> true | _ -> false\n\n let push x s = x :: s\n\n exception Empty\n\n let peek = function\n | [] -> raise Empty\n | x :: _ -> x\nend;; module type LIST_STACK = sig\n (** [Empty] is raised when an operation cannot be applied\n to an empty stack. *)\n exception Empty\n\n (** [empty] is the empty stack. *)\n val empty : 'a list\n\n (** [is_empty s] is whether [s] is empty. *)\n val is_empty : 'a list -> bool\n\n (** [push x s] pushes [x] onto the top of [s]. *)\n val push : 'a -> 'a list -> 'a list\n\n (** [peek s] is the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val peek : 'a list -> 'a\n\n (** [pop s] is all but the top element of [s].\n Raises [Empty] if [s] is empty. *)\n val pop : 'a list -> 'a list\nend;; module ListStack : LIST_STACK = struct\n let empty = []\n\n let is_empty = function [] -> true | _ -> false\n\n let push x s = x :: s\n\n exception Empty\n\n let peek = function\n | [] -> raise Empty\n | x :: _ -> x\n\n let pop = function\n | [] -> raise Empty\n | _ :: s -> s\n\n let internal = function | [] -> [] | _ -> [];;\nend;; ListStack.internal;; ListStack.pop;;