I am creating a Rationals structure (int * int), and one of my functions:
fun diff ((n, d), (n', d')) = let val (top, bot) = sum ((n, d), (~n', d'))
in
(top / gcd(top, bot), bot / gcd(top, bot))
end
gcd gives me the largest common denominator, so I am not getting 2/8, but rather 1/4, as it should be. gcd uses mod to search for gcd, so it returns an int. But I can not force the division expression to be typed as int. When I tried to add : int * intdiff to the end of the description, it gives me an error like that the expressions real * real and int * int do not match.
How can I force integer division or apply an expression to the whole? If both options are possible, which one is better?
source
share