oded@oded-XPS13-9333:~/pl16/ocaml$ utop ------------+------------------------------------------------------------+------------ | Welcome to utop version 1.15 (using OCaml version 4.01.0)! | +------------------------------------------------------------+ 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 Type #utop_help for help about using utop. -( 15:15:49 )-< command 0 >--------------------------------------------{ counter: 0 }- utop # open Core.Std;; -( 15:15:50 )-< command 1 >--------------------------------------------{ counter: 0 }- utop # 1 + 1;; - : int = 2 -( 15:16:22 )-< command 2 >--------------------------------------------{ counter: 0 }- utop # 1.5 + 3.6 ;; Error: This expression has type float but an expression was expected of type int -( 15:17:45 )-< command 3 >--------------------------------------------{ counter: 0 }- utop # 1.5 +. 3.6 ;; - : float = 5.1 -( 15:18:01 )-< command 4 >--------------------------------------------{ counter: 0 }- utop # (+);; - : int -> int -> int = -( 15:18:28 )-< command 5 >--------------------------------------------{ counter: 0 }- utop # (+.);; - : float -> float -> float = -( 15:18:54 )-< command 6 >--------------------------------------------{ counter: 0 }- utop # (+) 1 5;; - : int = 6 -( 15:19:13 )-< command 7 >--------------------------------------------{ counter: 0 }- utop # (+) 1;; - : int -> int = -( 15:19:29 )-< command 8 >--------------------------------------------{ counter: 0 }- utop # let f = (+) 1;; val f : int -> int = -( 15:19:39 )-< command 9 >--------------------------------------------{ counter: 0 }- utop # f;; - : int -> int = -( 15:20:02 )-< command 10 >-------------------------------------------{ counter: 0 }- utop # f 7;; - : int = 8 -( 15:20:04 )-< command 11 >-------------------------------------------{ counter: 0 }- utop # f 10;; - : int = 11 -( 15:20:10 )-< command 12 >-------------------------------------------{ counter: 0 }- utop # let sum_if_true test first second = (if test first then first else 0) + (if test second then second else 0) ;; val sum_if_true : (int -> bool) -> int -> int -> int = -( 15:20:13 )-< command 13 >-------------------------------------------{ counter: 0 }- utop # let x = 5;; val x : int = 5 -( 15:21:41 )-< command 14 >-------------------------------------------{ counter: 0 }- utop # x;; - : int = 5 -( 15:22:03 )-< command 15 >-------------------------------------------{ counter: 0 }- utop # x + x;; - : int = 10 -( 15:22:06 )-< command 16 >-------------------------------------------{ counter: 0 }- utop # let f x = 2 * x;; val f : int -> int = -( 15:22:08 )-< command 17 >-------------------------------------------{ counter: 0 }- utop # f 4;; - : int = 8 -( 15:22:16 )-< command 18 >-------------------------------------------{ counter: 0 }- utop # let is_even n = n % 2 = 0;; val is_even : int -> bool = -( 15:22:38 )-< command 19 >-------------------------------------------{ counter: 0 }- utop # is_even 7;; - : bool = false -( 15:25:27 )-< command 20 >-------------------------------------------{ counter: 0 }- utop # is_even 8;; - : bool = true -( 15:25:33 )-< command 21 >-------------------------------------------{ counter: 0 }- utop # sum_if_true is_even 12 20 ;; - : int = 32 -( 15:25:35 )-< command 22 >-------------------------------------------{ counter: 0 }- utop # sum_if_true is_even 12 21 ;; - : int = 12 -( 15:25:50 )-< command 23 >-------------------------------------------{ counter: 0 }- utop # sum_if_true is_even 13 21 ;; - : int = 0 -( 15:25:55 )-< command 24 >-------------------------------------------{ counter: 0 }- utop # let first_if_true test x y = if test x then x else y ;; val first_if_true : ('a -> bool) -> 'a -> 'a -> 'a = -( 15:25:59 )-< command 25 >-------------------------------------------{ counter: 0 }- utop # first_if_true is_even 10 20 ;; - : int = 10 -( 15:27:14 )-< command 26 >-------------------------------------------{ counter: 0 }- utop # first_if_true is_even 11 20 ;; - : int = 20 -( 15:29:12 )-< command 27 >-------------------------------------------{ counter: 0 }- utop # first_if_true is_even 11 21 ;; - : int = 21 -( 15:29:17 )-< command 28 >-------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x % 2 = 0) 11 21 ;; - : int = 21 -( 15:29:22 )-< command 29 >-------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x > 0.0) 11 21 ;; Error: This expression has type int but an expression was expected of type float -( 15:29:52 )-< command 30 >-------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x > 0.0) 11.0 21.0 ;; - : float = 11. -( 15:30:28 )-< command 31 >-------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x > 0.0) -11.0 21.0 ;; Error: This expression has type float -> float -> float but an expression was expected of type int -( 15:30:33 )-< command 32 >-------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x > 0.0) (-11.0) 21.0 ;; - : float = 21. -( 15:30:38 )-< command 33 >-------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x > 0.0) (-11.0) 21 ;; Error: This expression has type int but an expression was expected of type float -( 15:30:45 )-< command 34 >-------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x = "") "Hello" "World";; - : string = "World" -( 15:30:55 )-< command 35 >-------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x = "") "" "World";; - : string = "" -( 14:24:56 )-< command 21 >--------------------------------------------------------------{ counter: 0 }- utop # first_if_true is_even "A" "B" ;; Error: This expression has type string but an expression was expected of type int -( 14:25:00 )-< command 22 >--------------------------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x="") "A" "B" ;; - : string = "B" -( 14:25:22 )-< command 23 >--------------------------------------------------------------{ counter: 0 }- utop # first_if_true (fun x -> x="") "" "B" ;; - : string = "" -( 15:23:17 )-< command 25 >-------------------------------------------{ counter: 0 }- utop # let x = 10 in let y = x + x in first_if_true is_even x y ;; - : int = 10 -( 15:31:48 )-< command 37 >-------------------------------------------{ counter: 0 }- utop # let a = 1, "Hello", 3.0;; val a : int * string * float = (1, "Hello", 3.) -( 15:34:11 )-< command 38 >-------------------------------------------{ counter: 0 }- utop # let x, y, z = a;; val x : int = 1 val y : string = "Hello" val z : float = 3. -( 15:34:16 )-< command 39 >-------------------------------------------{ counter: 0 }- utop # let x, y = a;; Error: This expression has type int * string * float but an expression was expected of type 'a * 'b -( 15:34:51 )-< command 40 >-------------------------------------------{ counter: 0 }- utop # let x = 4;; val x : int = 4 -( 15:35:06 )-< command 41 >-------------------------------------------{ counter: 0 }- utop # let x = 5;; val x : int = 5 -( 15:35:32 )-< command 42 >-------------------------------------------{ counter: 0 }- utop # let x = 1,2;; val x : int * int = (1, 2) -( 15:35:37 )-< command 43 >-------------------------------------------{ counter: 0 }- utop # let x,y = x;; val x : int = 1 val y : int = 2 -( 15:36:46 )-< command 44 >-------------------------------------------{ counter: 0 }- utop # let distance (x1,y1) (x2,y2) = sqrt ((x1 -. x2) ** 2. +. (y1 -. y2) ** 2.) ;; val distance : float * float -> float * float -> float = -( 15:36:51 )-< command 45 >-------------------------------------------{ counter: 0 }- utop # let distance2 x1 y1 x2 y2 = sqrt ((x1 -. x2) ** 2. +. (y1 -. y2) ** 2.) ;; val distance2 : float -> float -> float -> float -> float = -( 16:27:49 )-< command 31 >-------------------------------------------{ counter: 0 }- utop # let g = distance (1.0,1.0);; val g : float * float -> float = -( 16:28:17 )-< command 32 >-------------------------------------------{ counter: 0 }- utop # g (5.0, 4.0);; - : float = 5. -( 16:30:11 )-< command 34 >-------------------------------------------{ counter: 0 }- utop # distance (1., 1.) (5., 4.);; - : float = 5. -( 15:37:40 )-< command 46 >-------------------------------------------{ counter: 0 }- utop # [1;2;3];; - : int list = [1; 2; 3] -( 15:38:17 )-< command 47 >-------------------------------------------{ counter: 0 }- utop # [1,2,3];; - : (int * int * int) list = [(1, 2, 3)] -( 15:39:22 )-< command 48 >-------------------------------------------{ counter: 0 }- utop # [1;2;3] @ [10;20];; - : int list = [1; 2; 3; 10; 20] -( 15:39:32 )-< command 49 >-------------------------------------------{ counter: 0 }- utop # 0 :: [10;20];; - : int list = [0; 10; 20] -( 15:32:15 )-< command 42 >-------------------------------------------{ counter: 0 }- utop # 1 :: (2 :: (3 :: []));; - : int list = [1; 2; 3] -( 15:32:55 )-< command 43 >-------------------------------------------{ counter: 0 }- utop # 1 :: 2 :: 3 :: [];; - : int list = [1; 2; 3] -( 15:40:00 )-< command 53 >-------------------------------------------{ counter: 0 }- utop # let x :: y = [1;2;3;4] ;; Characters 4-10: Warning 8: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] val x : int = 1 val y : int list = [2; 3; 4] -( 15:43:20 )-< command 54 >-------------------------------------------{ counter: 0 }- utop # let lst = [1;2;3;4];; val lst : int list = [1; 2; 3; 4] -( 15:43:42 )-< command 55 >-------------------------------------------{ counter: 0 }- utop # let x :: y = lst ;; Characters 4-10: Warning 8: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: [] val x : int = 1 val y : int list = [2; 3; 4] -( 15:44:28 )-< command 56 >-------------------------------------------{ counter: 0 }- utop # [1] = 1 :: [];; - : bool = true -( 15:31:01 )-< command 38 >-------------------------------------------{ counter: 0 }- utop # [1,2,3] @ [4;5];; Error: This expression has type int but an expression was expected of type int * int * int -( 15:34:56 )-< command 47 >-------------------------------------------{ counter: 0 }- utop # 5;; - : int = 5 -( 15:36:25 )-< command 48 >-------------------------------------------{ counter: 0 }- utop # Some 5;; - : int option = Some 5 -( 15:42:59 )-< command 49 >-------------------------------------------{ counter: 0 }- utop # None;; - : 'a option = None Here we switched to the book (https://realworldocaml.org/) and went over the examples of recursive list functions from Chapter 3 and then the example of using variant types to define colors from Chapter 6. At home, you are expected to go through Chapters 1,2,3,5,6 of the book, which cover most of OCaml's basics.