[Haskell-cafe] A question about "monad laws"

Jan-Willem Maessen jmaessen at alum.mit.edu
Tue Feb 12 09:12:40 EST 2008

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

> On Feb 11, 2008 10:18 PM, Uwe Hollerbach <uhollerbach at 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

More information about the Haskell-Cafe mailing list