bash-3.2$ cd courses/cs421/fa2014/
bash-3.2$ svn commit -m ""
Sending        public_html/lectures/01-02-intro.ppt
Transmitting file data .
Committed revision 4331.
bash-3.2$ cd public_html/lectures/
bash-3.2$ ocaml
        OCaml version 4.01.0

# 2 + 3;;  (* expression *)
- : int = 5
# 3 < 2;;  (* declaration *)
- : bool = false
# "Hi there";;  (* has type string *)
- : string = "Hi there"
# print_string "Hello world\n";;  (* has type unit *)
Hello world
- : unit = ()
# (print_string "Bye\n"; 25);;  (* Sequence of exp *)
Bye
- : int = 25
# let test = 3 < 2;;  (* declaration *)
val test : bool = false
# let a = 1 let b = a + 4;; (* Sequence of dec *)
val a : int = 1
val b : int = 5
# let test = 3.7;;
val test : float = 3.7
# let b = 5 * 4 in 2 * b;;
- : int = 40
# let c =
    let b = a + a
    in b * b;;
val c : int = 4
# b;;
- : int = 5
# true;;
- : bool = true
# false;;
- : bool = false
# if y > x then 25 else 0;;
Characters 3-4:
  if y > x then 25 else 0;;
     ^
Error: Unbound value y
# if b > a then 25 else 0;;
- : int = 25
# 3 > 1 && 4 > 6;;
- : bool = false
# 3 > 1 || 4 > 6;;
- : bool = true
# (print_string "Hi\n"; 3 > 1) || 4 > 6;;
Hi
- : bool = true
# 3 > 1 || (print_string "Bye\n"; 4 > 6);;
- : bool = true
# not (4 > 6);;
- : bool = true
# let s = (5,"hi",3.2);;
val s : int * string * float = (5, "hi", 3.2)
# let (a,b,c) = s;;
val a : int = 5
val b : string = "hi"
val c : float = 3.2
# let x = 2, 9.3;; (* tuples don't require parens in Ocaml *)
val x : int * float = (2, 9.3)
# let d = ((1,4,62),("bye",15),73.95);;
val d : (int * int * int) * (string * int) * float =
  ((1, 4, 62), ("bye", 15), 73.95)
# let (p,(st,_),_) = d;;
val p : int * int * int = (1, 4, 62)
val st : string = "bye"
# let plus_two n = n + 2;;
val plus_two : int -> int = <fun>
# plus_two 17;;
- : int = 19
# fun n -> n + 2;;
- : int -> int = <fun>
# (fun n -> n + 2) 17;;
- : int = 19
# let plus_two n = n + 2;;
val plus_two : int -> int = <fun>
# plus_two 17;;
- : int = 19
# let plus_two = fun n -> n + 2;;
val plus_two : int -> int = <fun>
# plus_two 14;;
- : int = 16
# (fun x -> x * 3) 5;;   (* An application *)
- : int = 15
# ((fun y -> y +. 2.0), (fun z -> z * 3));;  (* As data *)
- : (float -> float) * (int -> int) = (<fun>, <fun>)
# let x = 12;;
val x : int = 12
# let plus_x y = y + x;;
val plus_x : int -> int = <fun>
# plus_x 3;;
- : int = 15
# let x = 7;;  (* Redecaration, Not an update *)
val x : int = 7
# plus_x 3;;
- : int = 15
# let add_three x y z = x + y + z;;
val add_three : int -> int -> int -> int = <fun>
# let t = add_three 6 3 2;;
val t : int = 11
# let h = add_three 5 4;;
val h : int -> int = <fun>
# h 3;;
- : int = 12
# h 7;;
- : int = 16
# let thrice f x = f (f (f x));;
val thrice : ('a -> 'a) -> 'a -> 'a = <fun>
# let g = thrice plus_two;;
val g : int -> int = <fun>
# g 4;;
- : int = 10
# thrice (fun s -> "Hi! " ^ s) "Good-bye!";;
- : string = "Hi! Hi! Hi! Good-bye!"
# let rec factorial n =
    if n = 0 then 1 else n * factorial (n - 1);;
  val factorial : int -> int = <fun>
# factorial 5;;
- : int = 120
# let rec factorial n =
    match n
    with 0 -> 1
  | _ -> n * factorial (n - 1);;
      val factorial : int -> int = <fun>
# factorial 5;;
- : int = 120
# let fst_of_3 (x,_,_) = x;;
val fst_of_3 : 'a * 'b * 'c -> 'a = <fun>
# s;;
- : int * string * float = (5, "hi", 3.2)
# fst_of_3 s;;
- : int = 5
# fst_of_3 d;;
- : int * int * int = (1, 4, 62)
#