laptop% ocaml Objective Caml version 3.10.0 # 5 ;; - : int = 5 # 5 + 6 ;; - : int = 11 # 5 + 6 ;; - : int = 11 # true ;; - : bool = true # false ;; - : bool = false # 1 < 2 ;; - : bool = true # "apple";; - : string = "apple" # 'a';; - : char = 'a' # fun x -> x;; - : 'a -> 'a = # fun (x : int) -> x;; - : int -> int = # (fun x -> x) 10;; - : int = 10 # (fun x -> x) (10);; - : int = 10 # fun x -> x 10;; - : (int -> 'a) -> 'a = # 1 + (fun x -> x) (10);; - : int = 11 # 1 + fun x -> x 10;; Characters 4-17: 1 + fun x -> x 10;; ^^^^^^^^^^^^^ This expression should not be a function, the expected type is int # let f = fun x -> x;; val f : 'a -> 'a = # f (10);; - : int = 10 # f 10;; - : int = 10 # let n = 7;; val n : int = 7 # n ;; - : int = 7 # fun x y -> x + y;; - : int -> int -> int = # fun (x, y) -> x + y;; - : int * int -> int = # let f = fun (x, y) -> x + y;; val f : int * int -> int = # f (1, 2);; - : int = 3 # fun x -> fun y -> x + y;; - : int -> int -> int = # fun x, y -> x + y;; Characters 5-6: fun x, y -> x + y;; ^ Syntax error # fun ((x : int) , (y : bool)) -> x;; - : int * bool -> int = # (1 , 2);; - : int * int = (1, 2) # (1, bool);; Characters 4-8: (1, bool);; ^^^^ Unbound value bool # (1, true);; - : int * bool = (1, true) # (1, true, "apple", false);; - : int * bool * string * bool = (1, true, "apple", false) # ((1, 2), 3);; - : (int * int) * int = ((1, 2), 3) # (1, (2, 3));; - : int * (int * int) = (1, (2, 3)) # [1, 2, 3];; - : (int * int * int) list = [(1, 2, 3)] # [1 2 3];; Characters 1-2: [1 2 3];; ^ This expression is not a function, it cannot be applied # [1 :: 2 :: 3];; Characters 11-12: [1 :: 2 :: 3];; ^ This expression has type int but is here used with type int list # 1 :: [];; - : int list = [1] # 2 :: 1 :: [];; - : int list = [2; 1] # [1; 2; 3];; - : int list = [1; 2; 3] # [1; true];; Characters 4-8: [1; true];; ^^^^ This expression has type bool but is here used with type int # "apple" :: []; ;; - : string list = ["apple"] # [];; - : 'a list = [] # [1, 2, 3];; - : (int * int * int) list = [(1, 2, 3)] # let (a, b) = (1, 2);; val a : int = 1 val b : int = 2 # let (a, _) = (3, 4);; val a : int = 3 # let j = fun (x, _) -> x;; val j : 'a * 'b -> 'a = # let n = function (x, 0) -> true | (x, _) -> false;; val n : 'a * int -> bool = # n (100, 1);; - : bool = false # n (100, 0);; - : bool = true # let n = function (x, 0) -> true | (x, _) -> x;; val n : bool * int -> bool = # n (false, 0);; - : bool = true # n (false, 17);; - : bool = false # let q = function (0, x) -> (- x) | (1, z) -> 1 + z;; Characters 8-50: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: (2, _) let q = function (0, x) -> (- x) | (1, z) -> 1 + z;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ val q : int * int -> int = # q (0, 17);; - : int = -17 # q (1, 17);; - : int = 18 # q (2, 17);; Exception: Match_failure ("", 7, -24). # let q = function (_, x) -> (- x) | (1, z) -> 1 + z;; Characters 35-41: Warning U: this match case is unused. let q = function (_, x) -> (- x) | (1, z) -> 1 + z;; ^^^^^^ val q : int * int -> int = # match (1, 2) with (x, y) -> x + y;; - : int = 3 # match (1, 2) with (0, y) -> x + y | (_, y) -> y;; Characters 28-29: match (1, 2) with (0, y) -> x + y | (_, y) -> y;; ^ Unbound value x # match (1, 2) with (0, x) -> x +1 | (_, y) -> y;; - : int = 2 # let fact = function 0 -> 1 | n -> n * fact (n - 1);; Characters 38-42: let fact = function 0 -> 1 | n -> n * fact (n - 1);; ^^^^ Unbound value fact # let rec fact = function 0 -> 1 | n -> n * fact (n - 1);; val fact : int -> int = # fact 10;; - : int = 3628800 # let rec odd = function 0 -> false | even (n - 1);; Characters 41-42: let rec odd = function 0 -> false | even (n - 1);; ^ Syntax error # let rec odd = function 0 -> false | n -> even (n - 1);; Characters 41-45: let rec odd = function 0 -> false | n -> even (n - 1);; ^^^^ Unbound value even # let rec odd = function 0 -> false | n -> even (n - 1) and even = function 0 -> true | n -> odd (n - 1);; val odd : int -> bool = val even : int -> bool = # odd 57;; - : bool = true # let x = 10 in x;; - : int = 10 # x ;; Characters 0-1: x ^ Unbound value x # type t = I of int | B of bool;; type t = I of int | B of bool # I 10;; - : t = I 10 # B true;; - : t = B true # type T = I of int | B of bool;; Characters 5-6: type T = I of int | B of bool;; ^ Syntax error # type t = i of int | b of bool;; Characters 11-13: type t = i of int | b of bool;; ^^ Syntax error # let f = function (I i) -> i | (B true) -> 1 | (B false) -> 0;; val f : t -> int = # f (I 10);; - : int = 10 # f (B false);; - : int = 0 # type maybe = Nothing | Something of int;; type maybe = Nothing | Something of int # Nothing;; - : maybe = Nothing # Something 10;; - : maybe = Something 10 # (Nothing);; - : maybe = Nothing # Nothing ();; Characters 0-10: Nothing ();; ^^^^^^^^^^ The constructor Nothing expects 0 argument(s), but is here applied to 1 argument(s) # ();; - : unit = () # type maybe = Nothing | Something of int | More of (bool * bool);; type maybe = Nothing | Something of int | More of (bool * bool) # More (true, false);; - : maybe = More (true, false) # let rec len = function [] -> 0 | fst :: rst -> 1 + len rst;; val len : 'a list -> int = # len [0; 1; 2];; - : int = 3 # map; ;; Characters 0-4: map; ^^^^ Unbound value map # List.map;; - : ('a -> 'b) -> 'a list -> 'b list = # let rec sum = function [] -> 0 | fst :: rest -> fst + sum rst;; Characters 58-61: let rec sum = function [] -> 0 | fst :: rest -> fst + sum rst;; ^^^ Unbound value rst # let rec sum = function [] -> 0 | fst :: rst -> fst + sum rst;; val sum : int list -> int = # let rec len = function [] -> 0 | (fst : int) :: rst -> 1 + len rst;; val len : int list -> int = # let rec len : (int list -> int) = function [] -> 0 | fst :: rst -> 1 + len rst;; val len : int list -> int = #