On 6/20/07, Henning Thielemann <lemming@henning-thielemann.de> wrote:
What about the function isSquare?
isSquare :: (Integral a) => a -> Bool
isSquare n = (floor . sqrt $ fromIntegral n) ^ 2 == n
Is there any way to write that without the fromIntegral? If you leave out the fromIntegral and the explicit type signature, it type checks, but the type constraints are such that there are no actual types that you can call it on.
As I think about it more, I guess one of my biggest goals is essentially to have an integral type which can silently convert to a rational or floating type when necessary (e.g. you should be able to call sqrt on an integral type and have it implicitly convert to floating). Perhaps this actually has less to do with scripting-language-style numeric types than it does with languages (
e.g. Java) that do implicit type conversions in directions where no information is lost -- e.g. you can take the sqrt of an int and get a double, but if you want to change a double into an int you have to explicitly truncate or round or whatever.
-Brent