I teach myself Haskell.
I want to write a function that recursively finds the first number that has an integer square root and less than the starting number.
It looks like this:
findFirstSquare :: Int -> Int findFirstSquare x | x <= 0 = error "This function only works for 1 or above" | fromInteger(floor(sqrt(x))) == (sqrt x) = x | otherwise = intSqrt(x - 1)
But the GHC complains:
There is no instance for (RealFrac Int) resulting from using `floor 'at ...
However, if I introduce the following into GHCi, he will happily compile it:
fromInteger(floor(sqrt(4))) == (sqrt 4)
My question is: why am I getting a type error from an expression that compiles successfully in GHCi?
source share