One of the problems is that you return two different types: int for an empty list or a tuple otherwise. It must be one or the other.
Another problem is that you are trying to add 1 to test , but test is a function, not a value. You need to call a test for something else to return the value, but even then it should return a tuple that you cannot add to the integer.
I cannot understand what you want to do, but if you update your question with this information, I can help more.
Guess that I have what you want to count the positive numbers in the list, in which case you could write it like this:
let rec test l = match l with [] -> 0 | x::xs -> if x > 0 then 1 + (test xs) else test xs;;
Update : since you edited to clarify the problem, modify the above code as follows:
let test l = let rec test_helper l pos nonpos = match l with [] -> (pos, nonpos) | x::xs -> if x > 0 then test_helper xs 1+pos, nonpos else test_helper xs pos 1+nonpos in test_helper l 0 0;;
Using batteries helps in this case. It also makes tail-recursive, which is always good practice.
danben
source share