[Haskell-cafe] ANN: convertible (first release)
Duncan Coutts
duncan.coutts at worc.ox.ac.uk
Wed Jan 28 19:27:02 EST 2009
On Wed, 2009-01-28 at 18:41 -0500, Michael D. Adams wrote:
> On Wed, Jan 28, 2009 at 5:28 PM, wren ng thornton <wren at freegeek.org> wrote:
> > John Goerzen wrote:
> >> wren ng thornton wrote:
> >> I wonder if you would consider submitting a patch to base? It seems
> >> that this is a sore problem there, and ideally should be dealt with
> >> properly in base.
> >
> > As Bertram Felgenhauer says, it's not as easy as fixing base; the problem is
> > an error in the Haskell98 specification. The Float and Double types contain
> > exceptional values which cannot be represented in Rational (by definition).
> > The only Haskell98 solution is to raise an error when attempting to convert
> > those values into Rational, which isn't much of an improvement.
>
> Is there a good reason why Rational is defined in a way that it can
> not represent Nan, Inf and -Inf? (Any other exceptional values I
> forgot?) Would fixing the definition so that it can represent those
> values be sufficient to fix this entire problem?
It may well help conversions of floating point numbers through Rational
but the contrary argument is that Rational is a well defined concept and
that values like those do not belong in it.
The problem seems to be that the various real/float classes in the
Prelude cannot provide a class that allows conversions directly between
Double and Float without going via a universal type because the class
would either have to be multi-parameter or mention one of the types in
the class definition. For integral types it's no problem to go via
Integer but floating point types are a good deal more tricky.
Duncan
More information about the Haskell-Cafe
mailing list