let tuesday () = true;; let abbrev () = if tuesday() then let x = 2 + 3 in x + x else 0 ;; let add_one (x:int) : int = 1 + x;; let add_two (x:int) : int = add_one (add_one x);; let add_two' (x:int) : int = let add_one x = 1 + x in add_one (add_one x) ;; let x = 3;; let add_three (y:int) : int = y + x ;; let x = 4 ;; let add_four (y:int) : int = y + x ;; let add_seven (y:int) : int = add_three (add_four y) ;; let print_17 () = print_int (add_seven 10); print_newline() ;; let pair : int * int = (1,2) ;; let triple : string * int * bool = ("hello", 7 + 3, true) ;; let pair_of_pairs : char * (string * string) = ('a', ("hello", "goodbye")) ;; type point = float * float let distance (p1:point) (p2:point) : float = let (x1,y1) = p1 in let (x2,y2) = p2 in let square x = x *. x in sqrt (square (x2 -. x1) +. square (y2 -. y1)) ;; let p1 = (2.0,3.0);; let p2 = (0.0,1.0);; let mydist = distance p1 p2;; let slope (p1:point) (p2:point) : float option = let (x1,y1) = p1 in let (x2,y2) = p2 in let xd = x2 -. x1 in if xd != 0.0 then Some ((y2 -. y1) /. xd) else None ;; let print_slope (p1:point) (p2:point) : unit = match slope p1 p2 with Some s -> print_string ("Slope: " ^ string_of_float s) | None -> print_string "Vertical line.\n" ;; let distance2 (p1:point) (p2:point) : float = let square x = x *. x in match p1 with | (x1,y1) -> match p2 with | (x2,y2) -> sqrt (square (x2 -. x1) +. square (y2 -. y1)) ;; let distance3 (p1:point) (p2:point) : float = let square x = x *. x in match (p1, p2) with | ((x1,y1), (x2, y2)) -> sqrt (square (x2 -. x1) +. square (y2 -. y1)) ;; let small_prime (n:int) : bool = match n with | 2 -> true | 3 -> true | 5 -> true | _ -> false ;; let iffy (b:bool) : int = match b with | true -> 0 | false -> 1 ;; type java_pair = (int * int) option let swap_java_pair (p:java_pair) : java_pair = match p with | None -> None | Some (x,y) -> Some (y,x) type pair = int * int let swap_pair (p:pair) : pair = let (x,y) = p in (y,x)