Welcome to utop version 2.7.0 (using OCaml version 4.08.1)! utop[0]> let f x = let v1 = sqrt x and v2 = log x in (v1 +. v2) *. (v1 -. v2);; val f : float -> float = utop[1]> f 10.;; - : float = 4.69810188952160157 utop[2]> let g x = let v1 = sqrt x in let v2 = log x in (v1 +. v2) *. (v1 -. v2);; val g : float -> float = utop[3]> g 10.;; - : float = 4.69810188952160157 utop[4]> let g x = let v1 = sqrt x in let v2 = log v1 in (v1 +. v2) *. (v1 -. v2);; val g : float -> float = utop[5]> g 10.;; - : float = 8.6745254723804 utop[6]> let f x = (sqrt x +. log x.) *. (sqrt x -. log x);; Error: Syntax error: ')' expected, the highlighted '(' might be unmatched utop[7]> let f x = (sqrt x +. log x) *. (sqrt x -. log x);; val f : float -> float = utop[8]> f 10.;; - : float = 4.69810188952160157 utop[9]> let f2 x = let v1 = sqrt x and v2 = log x in (v1 +. v2) *. (v1 -. 2);; Line 4, characters 23-24: Error: This expression has type int but an expression was expected of type float utop[10]> let f2 x = let v1 = sqrt x and v2 = log x in (v1 +. v2) *. (v1 -. v2);; val f2 : float -> float = utop[11]> f2 10.;; - : float = 4.69810188952160157 utop[12]> let g x = sqrt x +. log (sqrt x);; val g : float -> float = utop[13]> let g2 x = let v1 = sqrt x in let v2 = log v1 in v1 +. v2;; val g2 : float -> float = utop[14]> g 10.;; - : float = 4.31357020666540247 utop[15]> g2 10.;; - : float = 4.31357020666540247 utop[16]> let f3 x = let v1, v2 = sqrt x, log x in (v1 +. v2) *. (v1 -. v2);; val f3 : float -> float = utop[17]> f3 10.;; - : float = 4.69810188952160157 utop[18]> fun x -> x + 3;; - : int -> int = utop[19]> (fun x -> x + 3) 10;; - : int = 13 utop[20]> (fun x -> x + 3) 20;; - : int = 23 utop[21]> 12 + 10;; - : int = 22 utop[22]> fun n x -> float_of_in n +. x;; Line 1, characters 11-22: Error: Unbound value float_of_in Hint: Did you mean float_of_int? utop[23]> fun n x -> float_of_int n +. x;; - : int -> float -> float = utop[24]> (fun n x -> float_of_int n +. x) 30 4.5;; - : float = 34.5 utop[25]> (fun;; n x -> float_of_int n +. x) 30 Error: Syntax error: operator expected. utop[26]> (fun n x -> float_of_int n +. x) 30;; - : float -> float = utop[27]> ((fun n x -> float_of_int n +. x) 30) 5.3;; - : float = 35.3 utop[28]> fun x -> 3 * x;; - : int -> int = utop[29]> (fun x -> 3 * x) 10;; - : int = 30 utop[30]> fun x -> 3 * x;; - : int -> int = utop[31]> 3 + 4;; - : int = 7 utop[32]> let toto = 12.;; val toto : float = 12. utop[33]> toto;; - : float = 12. utop[34]> let titi = 10;; val titi : int = 10 utop[35]> titi ;; - : int = 10 utop[36]> max titi 3;; - : int = 10 utop[37]> titi;; - : int = 10 utop[38]> fun x -> 3 * x;; - : int -> int = utop[39]> let tata = fun x -> 3 * x;; val tata : int -> int = utop[40]> tata 4;; - : int = 12 utop[41]> let f = fun x y -> 2 * x + 7;; val f : int -> 'a -> int = utop[42]> f 10 "toto";; - : int = 27 utop[43]> f;; - : int -> 'a -> int = utop[44]> f 10;; - : '_weak1 -> int = utop[45]> max;; - : 'a -> 'a -> 'a = utop[46]> max 10;; - : int -> int = utop[47]> let tata = fun x -> 3 * x;; val tata : int -> int = utop[48]> let tata x = 3 * x;; val tata : int -> int = utop[49]> let fact n = if n = 0 then 1 else n * fact (n - 1);; Line 4, characters 11-15: Error: Unbound value fact Hint: If this is a recursive definition, you should add the 'rec' keyword on line 1 utop[50]> let rec fact n = if n = 0 then 1 else n * fact (n - 1);; val fact : int -> int = utop[51]> fact 6;; - : int = 720 utop[52]> fact 10;; - : int = 3628800 utop[53]> fact 50;; - : int = -3258495067890909184 utop[54]> fact 5;; - : int = 120 utop[55]> let rec fact n = if n = 0 then 1 else n * fact n;; val fact : int -> int = utop[56]> fact 0;; - : int = 1 utop[57]> fact 1;; Stack overflow during evaluation (looping recursion?). utop[58]> let rec pow2 x = if x = 0 then 1 else 2 * pow2 (x - 1);; val pow2 : int -> int = utop[59]> pow2 10;; - : int = 1024 utop[60]> let rec pow2_log x = (* log *) if x = 0 then 1 else let y pow2_log (x / 2) in let c = y * y in if x mod 2 = 0 then c else c * 2 ;; Error: Syntax error: ')' expected, the highlighted '(' might be unmatched utop[61]> let rec pow2_log x = (* log *) if x = 0 then 1 else let y = pow2_log (x / 2) in let c = y * y in if x mod 2 = 0 then c else c * 2 ;; val pow2_log : int -> int = utop[62]> pow2_log 10;; - : int = 1024