I am trying to write a function that checks if a number is prime. I wrote this :
primeCheck :: Int -> Int -> Bool
primeCheck n i
| n == 2 = True
| i == 1 = True
| n `mod` i == 0 = False
| otherwise = primeCheck n (i -1)
isPrime :: Int -> Bool
isPrime n = primeCheck n (floor (sqrt n))
And I get these errors :
No instance for (RealFrac Int) arising from a use of
floor' Possible fix: add an instance declaration for (RealFrac Int) In the second argument ofprimeCheck', namely(floor (sqrt n))' In the expression: primeCheck n (floor (sqrt n)) In an equation forisPrime': isPrime n = primeCheck n (floor (sqrt n))No instance for (Floating Int) arising from a use of `sqrt' Possible fix: add an instance declaration for (Floating Int) In the first argument of `floor', namely `(sqrt n)' In the second argument of `primeCheck', namely `(floor (sqrt n))' In the expression: primeCheck n (floor (sqrt n)) Failed, modules loaded: none.
When I change the code to this to hopefully fix the problem:
primeCheck :: Int -> Int -> Bool
primeCheck n i
| n == 2 = True
| i == 1 = True
| n `mod` i == 0 = False
| otherwise = primeCheck n (i -1)
isPrime :: Int -> Bool
isPrime n = primeCheck n (floor (RealFrac (sqrt (Floating n))))
I get this :
Not in scope: data constructor `RealFrac'
Not in scope: data constructor `Floating'
How can I fix this?