The function `(y * y) <x 'is applied to two arguments, but its type` Bool' does not have

So I'm working on issue 31 .

I wrote the following function to determine if a number is prime:

isPrime :: Integer -> Bool

isPrime x = prime x 2
            where
            prime :: Integer -> Integer -> Bool
            prime x y | ((y*y) < x) and ((x `mod` y) /= 0) = prime x (y+1)
                      | ((y*y) >= x) = True
                      | otherwise = False

My logic performed a function isPrimeand had a function in isPrime, called primeto store 2 parameters, a number that I want to check to make sure it is simple ( x) and an iterator to check all numbers below sqrt x and see if they are divisible by x. primehas 3 protections:

| ((y*y) < x) and ((x `mod` y) == 0) = prime x (y+1)

: , x (((y*y) < x)), , x y (((x mod y) /= 0)), y, .

:

| ((y*y) >= x) = True

, , x , x .

, :

| otherwise = False

, - , .

, , , , , , , sqrt x sqrt x,

((y*y) < x)

GHCi :

The function `(y * y) < x' is applied to two arguments, but its type `Bool' has none

, < Bool, . , ? .

, , :

| ((y*y) >= x) = True

:

| ((y*y) > x) = True
+5
2

, ... <, :

((y*y) < x) and ((x `mod` y) /= 0)

, , and:

((y*y) < x) `and` ((x `mod` y) /= 0)

​​ , (.. , ++), .

, :

and ((y*y) < x) ((x `mod` y) /= 0)

. , , ((y*y) < x) . Haskell , - f x y f, x y.

and, Haskell ((y*y) < x) and ((x `mod` y) /= 0), ((y*y) < x) and ((x `mod` y) /= 0). , , ((y*y) < x) Bool, , " (y * y) < x , Bool ", Bool , .

...

, , , , && not and - and [Bool] -> Bool.

+10

, &&, and. .

+10

All Articles