Trying to wire my first program that tests for prime numbers starting at (2^82589933)-1
module Main where
import Data.List
import System.Environment
main :: IO()
factors :: Int -> [Int]
factors n = [x|x <-[1..n], mod n x == 0]
isPrime :: Int -> Bool
isPrime n = factors == [1,n]
p = 82589933
main = do
if isPrime (2^(p))-1 == True then p
else isPrime (2^(p+1))-1
I get this error after compiling in ghc with -o:
primes.hs:12:24: error:
• Couldn't match expected type ‘Int -> [Int]’
with actual type ‘[Int]’
• In the second argument of ‘(==)’, namely ‘[1, n]’
In the expression: factors == [1, n]
In an equation for ‘isPrime’: isPrime n = factors == [1, n]
|
12 | isPrime n = factors == [1,n]
| ^^^^^
primes.hs:18:7: error:
• Couldn't match expected type ‘IO ()’ with actual type ‘Bool’
• In the expression: isPrime (2 ^ (p + 1)) - 1
In a stmt of a 'do' block:
if isPrime (2 ^ (p)) - 1 == True then
p
else
isPrime (2 ^ (p + 1)) - 1
In the expression:
do if isPrime (2 ^ (p)) - 1 == True then
p
else
isPrime (2 ^ (p + 1)) - 1
|
18 | else isPrime (2^(p+1))-1
Wat do?