Haskell "No instance for" error
Haskell Error: "No instance for (Enum [Int])
Function definition problems (No instance for … arising from)
No instance for Num String arising from the literal `1'
I am very new to Haskell, and functional programming in general. In addition, I am aware that the questions above are very similar, but I have not been able to find a solution for my problem anywhere. The following code is meant to find the factors of a number input:
fc4 :: Double -> IO ()
check :: Double -> Double -> IO ()
fc4 a = check a (sqrt a)
check a b = if rem a b == 0 then print (b, div a b) else print () >> if b > 1 then check a (b-1) else putStrLn ("Done.")
I have attempted switching from Double
to Integer
and back with every possible combination, but every one fails with the same error:
No instance for (Integral Double) arising from a use of 'rem'
I have also tried explicitly using fromIntegral
and toInteger
on the arguments of rem
, but no combination I have attempted has avoided this problem. I also see by the documentation that the type for rem
is Integral a => a -> a -> a
, and so it seems that using the same type for a
and b
would always work, whether it be Double
or Integer
.
Am I on to something? Have I made some terrible rookie mistakes? For reference, here is a C++ version of what I hope to achieve. Thanks in advance!