On 6/20/07, <b class="gmail_sendername">Henning Thielemann</b> <<a href="mailto:firstname.lastname@example.org">email@example.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>How about<br> 1 % floor pi<br><br>?<br><br>Already two examples for the Wiki which I used to start the Wiki article:<br> <a href="http://www.haskell.org/haskellwiki/Generic_numeric_type">http://www.haskell.org/haskellwiki/Generic_numeric_type
</a><br></blockquote></div><br>What about the function isSquare?<br><br>isSquare :: (Integral a) => a -> Bool<br>isSquare n = (floor . sqrt $ fromIntegral n) ^ 2 == n<br><br>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.
<br><br>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.