This is what I have so far, I am pretty sure the function itself is correct but I am confused on what to do in the main = do block. The error I am getting is that the function wants an integer but I am giving it a string instead. I am assuming it has to do with the getLine part and the fact I am not checking to see if the entered number is an int.
factors :: Int -> [Int]
factors n = [x | x <- [1..n], mod n x == 0]
primeFactors :: Int -> [Int]
primeFactors n = [x | x <- [1..n], mod n x == 0, isPrime x]
isPrime x = (length (factors x)) == 2
main = do
putStrLn "Enter a number."
number <- getLine
let x = factors number
putStrLn x
The errors I get when I run this code:
primeFactor.hs:9:19: error:
• Couldn't match type ‘[Char]’ with ‘Int’ Expected type: Int Actual type: String • In the first argument of ‘factors’, namely ‘number’ In the expression: factors number In an equation for ‘x’: x = factors numberprimeFactor.hs:10:12: error:
• Couldn't match type ‘Int’ with ‘Char’ Expected type: String Actual type: [Int] • In the first argument of ‘putStrLn’, namely ‘x’ In a stmt of a 'do' block: putStrLn x In the expression: do { putStrLn "Enter a number."; number <- getLine; let x = factors number; putStrLn x }