Hi There,<br> Here is a very simple haskell program I have written to find whether a number is prime or not, which doesn't give me any compilation error but gives following run-time error :<br><br>Any help would help me move ahead, I know that the type concepts is what I am lacking, anly pointer to simple/good article/paper would definitely help.<br>
<br>Lots of thannx jut even to look at the mail :-)<br><br>Regards<br>Kaushal<br><br><font size="4"><u><b>Run Time Error :</b></u></font><br><br>kaushal > isPrime1 171<br><br><interactive>:1:0:<br> Ambiguous type variable `t' in the constraints:<br>
`Integral t'<br> arising from a use of `isPrime1' at <interactive>:1:0-11<br> `Floating t'<br> arising from a use of `isPrime1' at <interactive>:1:0-11<br> `RealFrac t'<br>
arising from a use of `isPrime1' at <interactive>:1:0-11<br> Probable fix: add a type signature that fixes these type variable(s)<br>kaushal > <br><br><font size="4"><u><b>Program :</b></u></font><br>
<br>isPrime1 x =<br> let canDivide num 0 = 0<br> canDivide num 1 = 0<br> canDivide num divisor = if ((mod num divisor) == 0) then 1<br> else canDivide num (divisor - 1)<br> in<br>
if ( x == 1 ) <br> then putStrLn("1 is Neither prime nor composite!!!") <br> else if ((canDivide x first_div) == 1) <br> then putStrLn(show(x) ++ " is not a Prime Number!!!")<br>
else putStrLn(show(x) ++ " is a Prime Number!!!")<br> where<br> first_div :: Integral a => a ; first_div = round (sqrt x)<br><br>