Welcome to utop version 2.7.0 (using OCaml version 4.08.1)! Findlib has been successfully loaded. Additional directives: #require "package";; to load a package #list;; to list the available packages #camlp4o;; to load camlp4 (standard syntax) #camlp4r;; to load camlp4 (revised syntax) #predicates "p,q,...";; to set these predicates Topfind.reset();; to force that packages will be reloaded #thread;; to enable threads utop[0]> ;; utop[1]> 3 + 3;; - : int = 6 utop[2]> let f x = x;; val f : 'a -> 'a = utop[3]> f 's';; - : char = 's' utop[4]> f 3;; - : int = 3 utop[5]> f 3.;; - : float = 3. utop[6]> ;;f utop[7]> f;; - : 'a -> 'a = utop[8]> let f x = x,x;; val f : 'a -> 'a * 'a = utop[9]> f 4;; - : int * int = (4, 4) utop[10]> let f x y = x, y;; val f : 'a -> 'b -> 'a * 'b = utop[11]> let f x y = x + 1, y;; val f : int -> 'a -> int * 'a = utop[12]> let f x y = x +. 1., y;; val f : float -> 'a -> float * 'a = utop[13]> let f (x : int) = x;; val f : int -> int = utop[14]> let f x = x ^ x;; val f : string -> string = utop[15]> let f x = x ^ (x + 1);; Line 1, characters 16-17: Error: This expression has type string but an expression was expected of type int utop[16]> let let carre x = x * x;; Error: Syntax error utop[17]> let carre x = x * x;; val carre : int -> int = utop[18]> sin;; - : float -> float = utop[19]> let poly a b c = fun x -> a*x*x + b*x + c;; val poly : int -> int -> int -> int -> int = utop[20]> let poly a b c x = a*x*x + b*x + c;; val poly : int -> int -> int -> int -> int = utop[21]> let poly = fun a b c x -> a*x*x + b*x + c;; val poly : int -> int -> int -> int -> int = utop[22]> let poly a = fun b c x -> a*x*x + b*x + c;; val poly : int -> int -> int -> int -> int = utop[23]> let poly a b = fun b c x -> a*x*x + b*x + c;; val poly : int -> 'a -> int -> int -> int -> int = utop[24]> poly 10;; - : '_weak1 -> int -> int -> int -> int = utop[25]> poly 10 5;; - : int -> int -> int -> int = utop[26]> poly 10 5 2;; - : int -> int -> int = utop[27]> poly 10 5 2 4;; - : int -> int = utop[28]> let poly a b = fun c x -> a*x*x + b*x + c;; val poly : int -> int -> int -> int -> int = utop[29]> poly 10 5 2 4;; - : int = 182 utop[30]> max;; - : 'a -> 'a -> 'a = utop[31]> max 1;; - : int -> int = utop[32]> max 1 4;; - : int = 4 utop[33]> let compose f g = fun x -> f (g x);; val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = utop[34]> compose sin asin;; - : float -> float = utop[35]> compose carre carre;; - : int -> int = utop[36]> (compose carre carre) 2;; - : int = 16 utop[37]> compose carre (fun x -> x + 3) 2;; - : int = 25 utop[38]> let bidon f = fun x -> f (f x) ;; val bidon : ('a -> 'a) -> 'a -> 'a = utop[39]> 3,4;; - : int * int = (3, 4) utop[40]> 3,4.0;; - : int * float = (3, 4.) utop[41]> fst 3,4.0;; Line 1, characters 4-5: Error: This expression has type int but an expression was expected of type 'a * 'b utop[42]> fst (3,4.0);; - : int = 3 utop[43]> snd (3,4.0);; - : float = 4. utop[44]> let c = (3,4);; val c : int * int = (3, 4) utop[45]> fst c;; - : int = 3 utop[46]> let c = 3,4;; val c : int * int = (3, 4) utop[47]> fst c;; - : int = 3 utop[48]> 2,4.5, "gerge", 'a';; - : int * float * string * char = (2, 4.5, "gerge", 'a') utop[49]> let couple_square x = x, x * x;; val couple_square : int -> int * int = utop[50]> couple_square 4;; - : int * int = (4, 16) utop[51]> couple_square 104;; - : int * int = (104, 10816) utop[52]> let pair x = x, x ;; val pair : 'a -> 'a * 'a = utop[53]> let pol (a,b,c) = fun x = a * x *x + b* x + c;; Error: Syntax error utop[54]> let pol (a,b,c) = fun x -> a * x *x + b* x + c;; val pol : int * int * int -> int -> int = utop[55]> pol 1 2 3;; Line 1, characters 0-3: Error: This function has type int * int * int -> int -> int It is applied to too many arguments; maybe you forgot a `;'. utop[56]> pol (1, 2, 3);; - : int -> int = utop[57]> poly 1 2 3;; - : int -> int = utop[58]> let s3 (i, j, f) = i + j + int_of_float f;; val s3 : int * int * float -> int = utop[59]> s3 (2, 4, 4.5);; - : int = 10 utop[60]> s3 ;; - : int * int * float -> int = utop[61]> let tuple = 1,"deux",3,5;; val tuple : int * string * int * int = (1, "deux", 3, 5) utop[62]> let i, str, f = tuple in int_of_float f + i, str;; Line 1, characters 16-21: Error: This expression has type int * string * int * int but an expression was expected of type 'a * 'b * 'c utop[63]> let tuple = 1,"deux",3.5;; val tuple : int * string * float = (1, "deux", 3.5) utop[64]> let i, str, f = tuple in int_of_float f + i, str;; - : int * string = (4, "deux") utop[65]> type type point = float * float;; Error: Syntax error utop[66]> type point = float * float;; type point = float * float utop[67]> 3.2,3.4;; - : float * float = (3.2, 3.4) utop[68]> type point2D = Point of float * float ;; type point2D = Point of float * float utop[69]> Point(1.2,3.4);; - : point2D = Point (1.2, 3.4) utop[70]> let p0 = Point(0., 0.);; val p0 : point2D = Point (0., 0.) utop[71]> (3., 2);; - : float * int = (3., 2) utop[72]> (3., 2.);; - : float * float = (3., 2.) utop[73]> let pzero : point = Point(0., 0.);; Line 1, characters 20-33: Error: This expression has type point2D but an expression was expected of type point = float * float utop[74]> let pzero : point = 0., 0.;; val pzero : point = (0., 0.) utop[75]> let bool_or_int = int | bool;; Error: Syntax error utop[76]> type bool_or_int = int | bool;; Error: Syntax error utop[77]> 3/0;; Exception: Division_by_zero. utop[78]> type int_or_infinity = Infinity | Int of int;; type int_or_infinity = Infinity | Int of int utop[79]> Int 5;; - : int_or_infinity = Int 5 utop[80]> Infinity;; - : int_or_infinity = Infinity utop[81]> Int (- 2);; - : int_or_infinity = Int (-2) utop[82]> let div n d = if d = 0 then if n = 0 then failwith "0/0!" else Infinity else n / d;; Line 7, characters 7-12: Error: This expression has type int but an expression was expected of type int_or_infinity utop[83]> let div n d = if d = 0 then if n = 0 then failwith "0/0!" else Infinity else Int (n / d);; val div : int -> int -> int_or_infinity = utop[84]> div 0 0;; Exception: Failure "0/0!". utop[85]> div 2 0;; - : int_or_infinity = Infinity utop[86]> div 4 2;; - : int_or_infinity = Int 2 utop[87]> let Int x = div 4 2 in x;; Line 1, characters 0-24: Warning 8: this pattern-matching is not exhaustive. Here is an example of a case that is not matched: Infinity Line 1, characters 0-24: Warning 8: this pattern-matching is not exhaustive. Here is an example of a case that is not matched: Infinity - : int = 2 utop[88]> let Int x = Int 10 in x + 3;; Line 1, characters 0-27: - : int = 13 Warning 8: this pattern-matching is not exhaustive. Here is an example of a case that is not matched: Infinity Line 1, characters 0-27: Warning 8: this pattern-matching is not exhaustive. Here is an example of a case that is not matched: Infinity utop[89]> { Infinity, Int 0, Int 1, .....}type form = Square of float | Circle of float | Rectangle of float * float ;; Error: Syntax error utop[90]> 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[91]> Square 3.4;; - : form = Square 3.4 utop[92]> Rectangle 4.5 6.7;; Error: Syntax error utop[93]> Rectangle (4.5 6.7);; Line 1, characters 0-19: Error: The constructor Rectangle expects 2 argument(s), but is applied here to 1 argument(s) utop[94]> Rectangle (4.5, 6.7);; - : form = Rectangle (4.5, 6.7) utop[95]> let perimeter_rect w h = 2. *. (w +. h);; val perimeter_rect : float -> float -> float = utop[96]> let perimeter_circle r = 2. *. 3.14 *. r;; val perimeter_circle : float -> float = utop[97]> let perimeter form = match form with Rectangle(w, h) -> perimeter_rect w h | Circle r -> perimeter_circle r | Square c -> perimeter_rect w h ;; Line 5, characters 31-32: Error: Unbound value w utop[98]> let perimeter form = match form with Rectangle(w, h) -> perimeter_rect w h | Circle r -> perimeter_circle r | Square c -> perimeter_rect c c ;; val perimeter : form -> float = utop[99]> perimeter (Square 3.0);; - : float = 12. utop[100]> perimeter (Circle 3.0);; - : float = 18.84 utop[101]>