<div class="gmail_quote">2009/3/20 Brandon S. Allbery KF8NH <span dir="ltr"><<a href="mailto:allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On 2009 Mar 20, at 18:01, Sean Bartell wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
For a type "a" to be Fractional requires there to be:<br>
(/) :: a -> a -> a<br>
You can't divide an Int by another Int and (in general) get a third<br>
Int. You would probably want something like a "Fractionable"<br>
typeclass, with<br>
(/) :: a -> a -> b<br>
which would result in a Rational, but Haskell doesn't have this.<br>
</blockquote>
<br>
<br></div>
...but there is (%) :: (Integral a) => a -> a -> Ratio a<br><font color="#888888">
</font></blockquote></div><br>Thanks, I knew about % but didn't remember about it when I was working on this sample :) So that being said, consider the following:<br><br>Prelude Data.Ratio> let x = 5::Int<br>Prelude Data.Ratio> :t x<br>
x :: Int<br>Prelude Data.Ratio> :t (x%3)<br>(x%3) :: Ratio Int<br>Prelude Data.Ratio> let y = truncate (x%3)<br>Prelude Data.Ratio> :t y<br>y :: Integer<br><br>Why does y now have the type Integer instead of Int? <br>