let rec f1 = function | 0 -> 0 | n -> n + f1(n-1) let rec f2 n = match n with | 0 -> 0 | n -> n + f2 n-1 (* here f2 is always given the same n, so OCaml gives a stack overflow error *) let rec f3 n m = match n with | 0 -> m | n -> f3 (n-1) m + n (* here the same m is given all over again to f3. However, n decreases. Check m after calling this function. The result is the same as before calling it. *) let rec f4 n m k = match n with | 0 -> m + k | n -> 1 + f4 (n-1) m+1 k-1 (* OCaml says there is an error while calling f4 function: Error: This expression has type int -> 'a but an expression was expected of type int What OCaml interpreter knows about the types of the arguments of f4? n is clearly int, m and k are also int because we return m+k. Now for OCaml, f4 is a function int -> int -> int -> 'a. When OCaml parses the expression 1 + f4 (n-1) m+1 k-1, it sees that (f4 (n-1) m) is one of the components of the sum. So, checking the type of (f4 (n-1) m) OCaml sees that it's actually a function that maps one integer into a resulting value. Hence, it cannot apply the "+" operation over the function (f4 (n-1) m). Expected type is int. *)