let rec prime : int -> bool
= fun n -> let rec f a = if (a = 1) then 1
else if (n mod a) = 0 then 0
else if ((f a-1) = 1) then 1
else 0
in
if ((f n-1) = 1) then true
else false
As you can see from my code, I want to implement a function which can tell given number is prime or not.
I can compile and run this code, but for all X function tell "false".
Why this happens?
Thanks in advance. :)
f n - 1thanf n-1which many beginners misread asf (n-1). - camlspotter