Welcome to utop version 2.13.1 (using OCaml version 4.13.1)! utop[0]> 2,3;; - : int * int = (2, 3) utop[1]> 2,"toto";; - : int * string = (2, "toto") utop[2]> let couple_square x = x, x * x;; val couple_square : int -> int * int = utop[3]> let couple_truc x = x, (x, x);; val couple_truc : 'a -> 'a * ('a * 'a) = utop[4]> 1,2,3;; - : int * int * int = (1, 2, 3) utop[5]> (1,2,3), "t";; - : (int * int * int) * string = ((1, 2, 3), "t") utop[6]> let f i j f = i + j + int_of_float f;; val f : int -> int -> float -> int = utop[7]> f 2 3 4.;; - : int = 9 utop[8]> let s3 (i, j, f) = i + j + int_of_float f;; val s3 : int * int * float -> int = utop[9]> f 2 3 4.;; - : int = 9 utop[10]> s3 2 3 4.;; Error: This function has type int * int * float -> int It is applied to too many arguments; maybe you forgot a `;'. utop[11]> s3 (2, 3, 4.);; - : int = 9 utop[12]> f 2;; - : int -> float -> int = utop[13]> let s3 (i, j, f) = i + j + int_of_float f, 30;; val s3 : int * int * float -> int * int = utop[14]> s3 (2, 3, 4.);; - : int * int = (9, 30) utop[15]> let tuple = 1, "deux", 3.5;; val tuple : int * string * float = (1, "deux", 3.5) utop[16]> let i, str, f = tuple in i + int_of_float f, str ;; - : int * string = (4, "deux") utop[17]> type point2D = float * float;; type point2D = float * float utop[18]> 2.2, 4.;; - : float * float = (2.2, 4.) utop[19]> type point2D = Point of float * float;; type point2D = Point of float * float utop[20]> Point (3., 4.);; - : point2D = Point (3., 4.) utop[21]> let p = Point (3., 4.);; val p : point2D = Point (3., 4.) utop[22]> let Point (x, y) = p in (x,x,y);; - : float * float * float = (3., 3., 4.) utop[23]> type int_or_infinity = Int of int | Infinity;; type int_or_infinity = Int of int | Infinity utop[24]> Int (4);; - : int_or_infinity = Int 4 utop[25]> Int 4;; - : int_or_infinity = Int 4 utop[26]> Int -4;; Error: The constructor Int expects 1 argument(s), but is applied here to 0 argument(s) utop[27]> Int (-4);; - : int_or_infinity = Int (-4) utop[28]> Infinity;; - : int_or_infinity = Infinity utop[29]> let div n d = if d = 0 then if n = 0 then failwith "0/0 undefined" else Infinity else n / d;; Error: This expression has type int but an expression was expected of type int_or_infinity utop[30]> let div n d = if d = 0 then if n = 0 then failwith "0/0 undefined" else Infinity else Int (n / d);; val div : int -> int -> int_or_infinity = utop[31]> div 0 0;; Exception: Failure "0/0 undefined". utop[32]> div 3 0;; - : int_or_infinity = Infinity utop[33]> div 10 3;; - : int_or_infinity = Int 3 utop[34]> type form = Square of float | Circle of float | Rectangle of float * float;; type form = Square of float | Circle of float | Rectangle of float * float utop[35]> Rectangle (10., 4.);; - : form = Rectangle (10., 4.) utop[36]> Circle 10.;; - : form = Circle 10. utop[37]> Square 10.;; - : form = Square 10. utop[38]> let r = Rectangle (10., 4.);; val r : form = Rectangle (10., 4.) utop[39]> let perimeter_rect w h = 2. *. (w +. h);; val perimeter_rect : float -> float -> float = utop[40]> perimeter_rect 10. 4.;; - : float = 28. utop[41]> let perimeter_circle r = 2. *. 3.14 *.r;; val perimeter_circle : float -> float = utop[42]> let perimeter_square c = perimeter_rect c c;; val perimeter_square : float -> float = utop[43]> let perimeter form = match form with Rectangle (w, h) -> perimeter_rect w h | Circle r -> perimeter_circle r | Square c - > perimeter_square c;; Error: Syntax error utop[44]> let perimeter form = match form with Rectangle (w, h) -> perimeter_rect w h | Circle r -> perimeter_circle r | Square c -> perimeter_square c;; val perimeter : form -> float = utop[45]> perimer r;; Error: Unbound value perimer Hint: Did you mean perimeter? utop[46]> perimeter r;; - : float = 28. utop[47]> perimeter (Square 4);; Error: This expression has type int but an expression was expected of type float Hint: Did you mean `4.'? utop[48]> perimeter (Square 4.);; - : float = 16. utop[49]> perimeter Rectangle(3., 5.);; Error: This function has type form -> float It is applied to too many arguments; maybe you forgot a `;'. utop[50]> perimeter (Rectangle(3., 5.));; - : float = 16. utop[51]> let _ = 4.;; - : float = 4. utop[52]> tuple;; - : int * string * float = (1, "deux", 3.5) utop[53]> let x, _, z = tuple in x, z;; - : int * float = (1, 3.5) utop[54]> type couleur = Coeur | Pique | Carreau | Trefle;; type couleur = Coeur | Pique | Carreau | Trefle utop[55]> type carte = As of couleur | Numero of (couleur, int) | Roi of couleur | Dame of couleur | Valet of couleur;; Error: Syntax error utop[56]> type carte = As of couleur | Numero of couleur * int | Roi of couleur | Dame of couleur | Valet of couleur;; type carte = As of couleur | Numero of couleur * int | Roi of couleur | Dame of couleur | Valet of couleur utop[57]> Numero (Coeur, 7);; - : carte = Numero (Coeur, 7) utop[58]> let est_une_figure carte = match carte with As _ -> false | Numero (_, _) -> false | _ -> true;; val est_une_figure : carte -> bool = utop[59]> est_une_figure (Numero (Pique, 8));; - : bool = false utop[60]> est_une_figure (Roi Pique);; - : bool = true utop[61]> let couleur_carte carte = match carte with As c -> c |Numero (c, _) -> c |Roi c -> c |Dame c -> c |Valet c -> c;; val couleur_carte : carte -> couleur = utop[62]> couleur_carte (Roi Pique);; - : couleur = Pique utop[63]> couleur_carte (Numero (Coeur, 2));; - : couleur = Coeur utop[64]> let couleur_carte carte = match carte with As c |Numero (c, _) |Roi c |Dame c |Valet c -> c;; val couleur_carte : carte -> couleur = utop[65]> let fib n = if n = 0 then 1 else if n = 1 then 1 else fib (n - 2) + fib (n - 1);; Error: Unbound value fib Hint: If this is a recursive definition, you should add the 'rec' keyword on line 1 utop[66]> let rec fib n = if n = 0 then 1 else if n = 1 then 1 else fib (n - 2) + fib (n - 1);; val fib : int -> int = utop[67]> fin 5;; Error: Unbound value fin Hint: Did you mean fib, min or sin? utop[68]> fib 5;; - : int = 8 utop[69]> type mycomplex = C of float * float;; type mycomplex = C of float * float utop[70]> let make_complex x y = C (x, y);; val make_complex : float -> float -> mycomplex = utop[71]> type mycomplex = C of float * float;; type mycomplex = C of float * float utop[72]> let realpart z = let C(x, _) = z in;; Error: Syntax error utop[73]> let realpart z = let C(x, _) = z in x;; val realpart : mycomplex -> float = utop[74]> let z = make_complex 3. 4.;; val z : mycomplex/2 = C (3., 4.) utop[75]> type mycomplex = C of float * float;; type mycomplex = C of float * float utop[76]> let make_complex x y = C (x, y);; val make_complex : float -> float -> mycomplex = utop[77]> let realpart z = let C(x, _) = z in x;; val realpart : mycomplex -> float = utop[78]> let z = make_complex 3. 4.;; val z : mycomplex = C (3., 4.) utop[79]> realpart z;; - : float = 3. utop[80]> let imagpart z = let C(_, y) = z in y;; val imagpart : mycomplex -> float = utop[81]> imagpart z;; - : float = 4. utop[82]> let c_add z1 z2 = make_complex (realpart z1 + realpart z2) (imagpart z1 + imagpart z2);; Error: This expression has type float but an expression was expected of type int utop[83]> let c_add z1 z2 = make_complex (realpart z1 +. realpart z2) (imagpart z1 +. imagpart z2);; val c_add : mycomplex -> mycomplex -> mycomplex = utop[84]> z;; - : mycomplex = C (3., 4.) utop[85]> c_add z z;; - : mycomplex = C (6., 8.) utop[86]> let c_i = let c_i = make_complex 0 1;; Error: Syntax error utop[87]> let c_i = make_complex 0. 1.;; val c_i : mycomplex = C (0., 1.) utop[88]>