Hugs Humor

Ross Paterson
Mon, 7 Jul 2003 12:05:49 +0100

On Mon, Jul 07, 2003 at 12:01:09PM +0200, Jerzy Karczmarczuk wrote:
> This is less a bug than a Nessie monster which haunts Hugs
> some centuries already, and on Internet the issue has been
> discussed at least 4 times. The old, experimental Gofer
> Prelude numeric functions were sometimes abominable, since
> Mark Jones concentrated on other things, and nobody really
> complained, people were busy with other stuff as well.
> But I can't understand why this continues until now. The
> obvious technique to convert floats to rationals is the
> continued fraction expansion which gives the simplified
> answer fast.

That would be because resources for Hugs maintenance are extremely
limited, and expertise in numerical methods even more lacking.
(e.g.: which approximant in the series should be chosen?)  I think
that if someone who knows about these things submitted a patch, and it
didn't increase the size of the Prelude (by much), it would be gratefully
accepted.  (That's probably true of all of Hugs.)

However, as far as I know, the outstanding numeric bugs in the Prelude are
- floating point literals of type Ratio t (mostly fixed in CVS), and
- the show instances for Float and Double (because the correct
  Numeric.showFloat would make the Prelude too large)

> I don't understand the remark that the internal arithmetic is
> binary. Sure, it is, so what?

In the case of 0.1::Rational, it shouldn't be using floating point.
The Report says this means fromRational (1%10), i.e. 1%10.
If Hugs implemented the Haskell definition directly, the question of
approximation wouldn't arise.  GHC does it that way, and usually removes
the fromRational at compile time, but Hugs isn't that clever.