So here is my code to find the factors of a number n, excluding n and 1.
factors :: Int -> [Int]
factors n = [x | x <- [2..(intSquareRoot n)], n `mod` x ==0]
intSquareRoot :: Int -> Int
intSquareRoot n = intSq n
where
intSq x
| x*x > n = intSq (x - 1)
| otherwise = x
it finds the factors of n upto sqrt(n), then I want to add the rest of factors. The code I want would look like this
factors :: Int -> [Int]
factors n = [x | x <- [2..(intSquareRoot n)], n `mod` x ==0]
++[1/x | x <- [2..(intSquareRoot n)], n `mod` x ==0]
But Haskell gives me the error that it expects a fractional number, which is understandable because I am dividing it. However, I know that for all x satisfying the conditions of the list, n/x will be an integer. How do I get around this error? Thanks in advance!