| |
comp.lang.haskell |
(snip) Prelude> :type sqrt ... note that the return type is the same as the argument type. From a Of course, Prelude> :type mod mod expects an integral n, and you already declared n to be Int. How about, proper_divisors n = [d | d <- [1 .. (floor . sqrt . fromIntegral) n], mod n d == 0] By the way, though I actually much prefer your convention, upper and Mark
> proper_divisors n = [d | d <- [1 .. (floor . sqrt) n], mod n d == 0]
(snip)
> No instance for (RealFrac Int)
> arising from a use of `floor' at pd.hs:2:37-41
(snip)
> No instance for (Floating Int)
> arising from a use of `sqrt' at pd.hs:2:45-48
to be instances of Floating and RealFrac, and Int isn't.
sqrt :: (Floating a) => a -> a
commonsense point of view, one can see part of the reason for the
complaint about Int as being that for things like sqrt (2::Int) you
couldn't return an Int answer (at least a correct one!).
mod :: (Integral a) => a -> a -> a
lower camel case seem to have established themselves as the Haskell way,
so normally one would name your function properDivisors.