Welcome to utop version 2.13.1 (using OCaml version 4.13.1)! utop[0]> let nb_sol a b = if a = 0 then if b = 0 then -1 else 0 else 1;; val nb_sol : int -> int -> int = utop[1]> nb_sol 0 0;; - : int = -1 utop[2]> nb_sol 0 1;; - : int = 0 utop[3]> nb_sol 2 3;; - : int = 1 utop[4]> let x = 1 in x + x;; - : int = 2 utop[5]> fun x -> x +3;; - : int -> int = utop[6]> (fun x -> x +3) 10;; - : int = 13 utop[7]> : int -> int = utop[6]> (fun x -> x +3) 10;; - : int = 13 utop[7]> fun x y -> float_of_int x +. y;; Error: Syntax error utop[8]> : int -> int = utop[6]> (fun x -> x +3) 10;; - : int = 13 utop[7]> fun x y -> float_of_int x +. y;; Error: Syntax error utop[9]> 1 ;; - : int = 1 utop[10]> : int -> int = utop[6]> - : int = 13 utop[7]> fun x y -> float_of_int x +. y;; Error: Syntax error utop[11]> : int -> int = utop[6]> fun x y -> float_of_int x +. y;; Error: Syntax error utop[12]> : int -> int = utop[6]> fun x y -> float_of_int x +. y;; Error: Syntax error utop[13]> fun x y -> float_of_int x +. y;; - : int -> float -> float = utop[14]> (fun x y -> float_of_int x +. y) 1.0;; Error: This expression has type float but an expression was expected of type int utop[15]> (fun x y -> float_of_int x +. y) 1;; - : float -> float = utop[16]> (fun x y -> float_of_int x +. y) 1 3.8;; - : float = 4.8 utop[17]> fun x -> 3 * x;; - : int -> int = utop[18]> (fun x y -> float_of_int x +. y) 1;; - : float -> float = utop[19]> float_of_int 4;; - : float = 4. utop[20]> int_of_float 4.4;; - : int = 4 utop[21]> let x = 100;; val x : int = 100 utop[22]> x;; - : int = 100 utop[23]> let x = 3 in x * x;; - : int = 9 utop[24]> let y = x + x in y * y;; - : int = 40000 utop[25]> let x = x + x in x * x;; - : int = 40000 utop[26]> fun x -> x + 3;; - : int -> int = utop[27]> let f = fun x -> x + 3;;;; val f : int -> int = utop[28]> f;; - : int -> int = utop[29]> f 10;; - : int = 13 utop[30]> let f = fun x y -> x + 3;;;; val f : int -> 'a -> int = utop[31]> let f = fun x y -> x + 3;;;; val f : int -> 'a -> int = utop[32]> f 10 "toto";; - : int = 13 utop[33]> let f x y = x + 3;; val f : int -> 'a -> int = utop[34]> f 10;; - : '_weak1 -> int = utop[35]> f (x * x +3);; - : '_weak2 -> int = utop[36]> let f x = x + 3;; val f : int -> int = utop[37]> f (x * x +3);; - : int = 10006 utop[38]> f x;; - : int = 103 utop[39]> let g x y = 2 * x + y;; val g : int -> int -> int = utop[40]> let h x = g x x;; val h : int -> int = utop[41]> f 3;; - : int = 6 utop[42]> h 3;; - : int = 9 utop[43]> let fact n = if n = 0 then 1 else n * fact (n - 1);; Error: Unbound value fact Hint: If this is a recursive definition, you should add the 'rec' keyword on line 1 utop[44]> let rec fact n = if n = 0 then 1 else n * fact (n - 1);; val fact : int -> int = utop[45]> fact 6;; - : int = 720 utop[46]> let rec pow2 x = if x = 0 then 1 else 2 * pow2 (x - 1);; val pow2 : int -> int = utop[47]> let f x =let id x = x;; Error: Syntax error utop[48]> let id x = x;; val id : 'a -> 'a = utop[49]> let f x = x, x;; val f : 'a -> 'a * 'a = utop[50]> let f x = x, x, x;; val f : 'a -> 'a * 'a * 'a = utop[51]> let f x y = x, x, y;; val f : 'a -> 'b -> 'a * 'a * 'b = utop[52]> let f x y = x + x, y;; val f : int -> 'a -> int * 'a = utop[53]> let f x = x ^ x;; val f : string -> string = utop[54]> let f x = x ^ (x + 1);; Error: This expression has type string but an expression was expected of type int utop[55]> let f x = x+ x > 4;; val f : int -> bool = utop[56]> 3,4;; - : int * int = (3, 4) utop[57]> sin;; - : float -> float = utop[58]> let compose f g = fun x -> f (g x);; val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = utop[59]> let compose_bis f g x = f (g x);; val compose_bis : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = utop[60]> int * int;; Error: Unbound value int utop[61]> 2,3;; - : int * int = (2, 3) utop[62]> (2,3);; - : int * int = (2, 3) utop[63]> fst (2,3);; - : int = 2 utop[64]> snd (2,3);; - : int = 3 utop[65]> 2, "toto", 3.4;; - : int * string * float = (2, "toto", 3.4) utop[66]> [2; "toto"; 3.4];; Error: This expression has type string but an expression was expected of type int utop[67]>