1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(* Compiles with 2 warnings *)
 *
 * 	| _ when (tab.(idx)) = value -> count_rec (idx + 1) (time + 1)
 *	| _ -> count_rec (idx + 1) time
 *  these cases are not used
 * But the result is always "0"
 *)


let count_occ tab value =
	let rec count_rec idx time =
		let n = Array.length tab in
		match idx with
		| n -> time
		| _ when (tab.(idx)) = value -> count_rec (idx + 1) (time + 1)
		| _ -> count_rec (idx + 1) time
	in
	count_rec 0 0
;;

(* This code doesn't compile *)

let count_occ tab value =
	let rec count_rec idx time =
		match idx with
		| (Array.lenght tab) -> time
		| _ when (tab.(idx)) = value -> count_rec (idx + 1) (time + 1)
		| _ -> count_rec (idx + 1) time
	in
	count_rec 0 0
;;






(* Doesn't work *)