Objective Caml version 3.06 # let l1 = [1;3;4];; val l1 : int list = [1; 3; 4] # let l2 = [4;5;6];; val l2 : int list = [4; 5; 6] # 7::l2;; - : int list = [7; 4; 5; 6] # l1 @ l2;; - : int list = [1; 3; 4; 4; 5; 6] # [[1;2];[3;4;5]];; - : int list list = [[1; 2]; [3; 4; 5]] # [[1;2];3];; This expression has type int but is here used with type int list # if true then 7;; This expression has type int but is here used with type unit # if true then 7 else 5;; - : int = 7 # 7; 5;; Warning: this expression should have type unit. - : int = 5 # (); 5;; - : int = 5 # print_string "hello "; print_string "there\n"; 2+3;; hello there - : int = 5 # let nsq n = match n with 0 -> 0 | n -> (2*n - 1) + (nsq (n - 1));; Unbound value nsq # let rec nsq n = match n with 0 -> 0 | n -> (2*n - 1) + (nsq (n - 1));; val nsq : int -> int = # nsq 1;; - : int = 1 # nsq 6;; - : int = 36 # (2*6 - 1) + ((2*5 - 1) + 16);; - : int = 36 # nsq -1;; This expression has type int -> int but is here used with type int # nsq (~1);; Syntax error # nsq (-1);; Stack overflow during evaluation (looping recursion?). # [2;3;4;6];; - : int list = [2; 3; 4; 6] # 2::3::4::6::[];; - : int list = [2; 3; 4; 6] # let rec length n lst = match lst with [] -> n | x::xs -> length (n + 1) xs;; val length : int -> 'a list -> int = # length [2;3;4;6];; This expression has type 'a list but is here used with type int # length 0 [2;3;4;6];; - : int = 4 # let length_rec = length;; val length_rec : int -> 'a list -> int = # let length lst = length_rec 0 lst;; val length : 'a list -> int = # length [2;3;4;6];; - : int = 4 # let rec max so_far lst = match lst with [] -> so_far | x::xs -> max (if x > so_far then x else so_far) xs;; val max : 'a -> 'a list -> 'a = # let rec max_top lst = match lst with [] -> raise "whatever" | x::xs -> max x xs;; This expression has type string but is here used with type exn # Exception "whatever";; Unbound constructor Exception # exception;; Syntax error # let append_newline str = str ^ "\n";; val append_newline : string -> string = # List.map append_newline ["hello";"i am";"a string";"or a few"];; - : string list = ["hello\n"; "i am\n"; "a string\n"; "or a few\n"] # (^);; - : string -> string -> string = # List.fold_left (^) "" ["a";"b"];; - : string = "ab" # List.fold_left (^) "" ( List.map append_newline ["hello";"i am";"a string";"or a few"]);;\ - : string = "hello\ni am\na string\nor a few\n" # print_string (List.fold_left (^) "" ( List.map append_newline ["hello";"i am";"a string";"or a few"]));; hello i am a string or a few - : unit = () # ;; Syntax error # let plus_two n = (n + 2);; val plus_two : int -> int = # let plus_four n = plus_two (plus_two n)); ;; Syntax error # let plus_four n = plus_two (plus_two n);; val plus_four : int -> int = # plus_four 3;; - : int = 7 # let compose f g = f (g x);; Unbound value x # let compose f g x = f (g x);; val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = # compose plus_two plus_two;; - : int -> int = # let plus_four_prime = compose plus_two plus_two;; val plus_four_prime : int -> int = # plus_four_prime 3;; - : int = 7 # let thrice f = compose f (compose f f);; val thrice : ('a -> 'a) -> 'a -> 'a = # thrice plus_two 4;; - : int = 10 # compose plus_two plus_two;; - : int -> int = # plus_two;; - : int -> int = # let curry f x y = f (x, y);; val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c = # let uncurry f (x, y) = f x y;; val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c = # (+);; - : int -> int -> int = # uncurry (+);; - : int * int -> int = # flip;; Unbound value flip # let flip f (x, y) = f (y, x);; val flip : ('a * 'b -> 'c) -> 'b * 'a -> 'c = # (-);; - : int -> int -> int = # (-) 3 5;; - : int = -2 # fun x y -> y - x;; - : int -> int -> int = # (fun x y -> y - x) 3 5;; - : int = 2 # flip (-);; This expression has type int -> int -> int but is here used with type 'a * 'b -> 'c # flip (uncurry (-));; - : int * int -> int = # curry (flip (uncurry (-))) 3 5;; - : int = 2 # let p2 f (x, y) -> f x;; Syntax error # let p2 f (x, y) = f x;; val p2 : ('a -> 'b) -> 'a * 'c -> 'b = #