laptop% ocaml Objective Caml version 3.06 # 5 ;; - : int = 5 # true ;; - : bool = true # 1 + 3 ;; - : int = 4 # fun (x : int) -> x ;; - : int -> int = # fun x -> x ;; - : 'a -> 'a = # (fun x -> x) 10 ;; - : int = 10 # ((fun (x) -> (x)) (10)) ;; - : int = 10 # 2 3;; Characters 0-1: 2 3;; ^ This expression is not a function, it cannot be applied # f(3);; Characters 0-1: f(3);; ^ Unbound value f # let i = fun x -> x ;; val i : 'a -> 'a = # let n = 7;; val n : int = 7 # i(n);; - : int = 7 # fun (x, y) -> x - y ;; - : int * int -> int = # fun (x : int, y : int) -> x - y ;; Characters 4-5: fun (x : int, y : int) -> x - y ;; ^ Syntax error: ')' expected, the highlighted '(' might be unmatched # fun ((x : int), (y : int)) -> x - y ;; - : int * int -> int = # let h = fun ((x : int), (y : int)) -> x - y ;; val h : int * int -> int = # h(1, 2) ;; - : int = -1 # (1, 2) ;; - : int * int = (1, 2) # let a = (1, 2);; val a : int * int = (1, 2) # h a;; - : int = -1 # 3 , true , 0 ;; - : int * bool * int = (3, true, 0) # (3, (5 , 7)) ;; - : int * (int * int) = (3, (5, 7)) # let j = fun (x, _) -> x ;; val j : 'a * 'b -> 'a = # j (1, 2) ;; - : int = 1 # j (3, (5, 6)) ;; - : int = 3 # let n = function 0 -> true | x -> false ;; val n : int -> bool = # n 0 ;; - : bool = true # n -10 ;; Characters 0-1: n -10 ;; ^ This expression has type int -> bool but is here used with type int # n (-10) ;; - : bool = false # 1 + _ ;; Characters 4-5: 1 + _ ;; ^ Syntax error # let p = function (0, x) -> (- x) | (y, z) -> y + z ;; val p : int * int -> int = # p (0, 2) ;; - : int = -2 # p (1, 3) ;; - : int = 4 # let q = function (0, x) -> (- x) | (1, z) -> 1 + z ;; Characters 8-50: Warning: 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, 4);; - : int = -4 # q (1, 5);; - : int = 6 # q (5, 6) ;; Exception: Match_failure ("", 8, 50). # let r = function (y, z) -> y + z | (0, x) -> (- x) ;; Characters 37-41: Warning: this match case is unused. let r = function (y, z) -> y + z | (0, x) -> (- x) ;; ^^^^ val r : int * int -> int = # match (1, 2) with (x, y) -> (y, z) ;; Characters 32-33: match (1, 2) with (x, y) -> (y, z) ;; ^ Unbound value z # match (1, 2) with (x, y) -> (y, x) ;; - : int * int = (2, 1) # match (1 > 3) with true -> "yes" | false -> "no" ;; - : string = "no" # if (1 > 3) then "yes" else "no";; - : string = "no" # 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 # fact 100;; - : int = 0 # let rec odd = 0 -> false | n -> even (n - 1) ;; Characters 16-18: let rec odd = 0 -> false | n -> 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 = # let f = function (x : int) -> 5 | (y : bool) -> 8 ;; Characters 35-36: let f = function (x : int) -> 5 | (y : bool) -> 8 ;; ^ This pattern matches values of type bool but is here used to match values of type int # type t = I of int | B or bool ;; Characters 22-24: type t = I of int | B or bool ;; ^^ Syntax error # type t = I of int | B of bool ;; type t = I of int | B of bool # 5 ;; - : int = 5 # I (5) ;; - : t = I 5 # B (false) ;; - : t = B false # let f = function (I x) -> 5 | (B y) -> 8 ;; val f : t -> int = # f (I 5) ;; - : int = 5 # f (B false) ;; - : int = 8 # type T = O of int ;; Characters 5-6: type T = O of int ;; ^ Syntax error # type t = o of int ;; Characters 11-13: type t = o of int ;; ^^ Syntax error # type t = Nothing | Something of int ;; type t = Nothing | Something of int # Nothing () ;; Characters 0-10: Nothing () ;; ^^^^^^^^^^ The constructor Nothing expects 0 argument(s), but is here applied to 1 argument(s) # Nothing;; - : t = Nothing # Something 8;; - : t = Something 8 # type t = Nothing | Something of int | More of (bool * bool) ;; type t = Nothing | Something of int | More of (bool * bool) # More(true, false) ;; - : t = More (true, false) # match More(true, false) with Nothing -> 7 | Something _ -> 9;; Characters 0-60: Warning: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: More _ match More(true, false) with Nothing -> 7 | Something _ -> 9;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exception: Match_failure ("", 0, 60). # let x = 5 in x + x ;; - : int = 10 # x;; Characters 0-1: x;; ^ Unbound value x #