[MLton] MLton.IntInf

Stephen Weeks MLton@mlton.org
Thu, 28 Apr 2005 14:40:27 -0700

> Your post inspired me to look at mlton/basic/rational.fun.

Warning: any code that is in the lib/mlton and is not used or exported
(such as functor Rational) should be treated with caution.  Such code
was inherited from libraries that I likely wrote long before MLton was
conceived and just came along for the ride when I grabbed the
libraries to use with MLton.  Such code is lightly tested at best.

> Since             p + nq
>         n + p/q = ---------
>                       q
>         val (op +) =
>            fn (T(n,one), T(p,q)) => T(p+n*q, q)
>             | (x,y) => let val (p,p',l) = scale(x,y)
>                            in T(p + p',l)
>                        end

Other than the fact that one cannot patern match on "one", this makes
sense.  Also, there seems to be a bug in the original code in that the
fraction should be reduced after computing the sum, in case that
introduces common factors.  This just drives the point home to treat
that code with caution.