I'm trying to put a 'print out' function call in a haskell function.
(a simple debug message).
Below is my code and error message from the compiler (ghc 6.10).
I don't quite understand why it is lumping the putstr call and the empty array.
The empty array is the return value for that particular case (the print out message is actually just a stub for now).
Any idea why this is isn't working?
Thanks
My Code:
isAFactor :: Integer -> Integer -> Bool isAFactor x y = x `mod` y == 0 findFactors :: Integer -> Integer -> [Integer] findFactors counter num = let quotient = div num 2 in if(counter > quotient) then do putStrLn ("factorList is : " ++ show quotient) (*** Line 10***) [] else if(isAFactor num counter) then [counter] ++ [quotient] ++ findFactors (counter + 1) num else findFactors (counter + 1) num
Error from ghc
test.hs:10:4: Couldn't match expected type `[a] -> [Integer]' against inferred type `IO ()' In the expression: putStrLn ("factorList is : " ++ show quotient) [] In the expression: do putStrLn ("factorList is : " ++ show quotient) [] In the expression: if (counter > quotient) then do putStrLn ("factorList is : " ++ show quotient) [] else if (isAFactor num counter) then [counter] ++ [quotient] ++ findFactors (counter + 1) num else findFactors (counter + 1) num