When you check the type of sqrt
Prelude> :t sqrt
sqrt :: Floating a => a -> a
It requires a floating number. It doesn't work in ghci. You might have tried calling it on a number and ghci would have inferred the type as Float.
Prelude> let a = 1 :: Int
Prelude> sqrt a
<interactive>:5:1:
No instance for (Floating Int) arising from a use of `sqrt'
Possible fix: add an instance declaration for (Floating Int)
In the expression: sqrt a
In an equation for `it': it = sqrt a
Now coming back to your code. The problem is in the expression [1 .. lim + 1]
. Arithmetic sequences can only be applied on values of type Enum a => a
. Since lim
is of type Floating a => a
, you need to convert it back to Integral a => a
by either taking the ceiling
or floor
. Just for information, Integral
class instance constraints the type to have an Enum
instance too.