On Feb 12, 2008 6:12 AM, Jan-Willem Maessen <jmaessen@alum.mit.edu> wrote:

On Feb 12, 2008, at 1:50 AM, David Benbennick wrote:

> On Feb 11, 2008 10:18 PM, Uwe Hollerbach <uhollerbach@gmail.com>
> wrote:
>> If I fire up ghci, import
>> Data.Ratio and GHC.Real, and then ask about the type of "infinity",
>> it
>> tells me Rational, which as far as I can tell is Ratio Integer...?
>
> Yes, Rational is Ratio Integer.  It might not be a good idea to import
> GHC.Real, since it doesn't seem to be documented at
> http://www.haskell.org/ghc/docs/latest/html/libraries/.  If you just
> import Data.Ratio, and define
>
>> pinf :: Integer
>> pinf = 1 % 0
>
>> ninf :: Integer
>> ninf = (-1) % 0
>
> Then things fail the way you expect (basically, Data.Ratio isn't
> written to support infinity).  But it's really odd the way the
> infinity from GHC.Real works.  Anyone have an explanation?

An educated guess here: the value in GHC.Real is designed to permit
fromRational to yield the appropriate high-precision floating value
for infinity (exploiting IEEE arithmetic in a simple, easily-
understood way).  If I'm right, it probably wasn't intended to be used
as a Rational at all, nor to be exploited by user code.

-Jan-Willem Maessen


Well... I dunno. Looking at the source to GHC.Real, I see

infinity, notANumber :: Rational
infinity   = 1 :% 0
notANumber = 0 :% 0
This is actually the reason I imported GHC.Real, because just plain % normalizes the rational number it creates, and that barfs very quickly when the denominator is 0. But the values themselves look perfectly reasonable... no?

Uwe