
Amanda Clare ajc@aber.ac.uk writes:
Does anyone know how I use Rationals in ghc? In nhc I can just write
let a = b % c
But ghc-5.00.2 gives the error message "Variable not in scope: `%'"
I've looked through the documentation and can't find any reference to a Rational library, or any other library that might have it. The package "std" has a Ratio.hi in the lib/imports directory (std isn't described in the documentation) but including this doesn't help - same error.
As you noticed, you need to import Ratio to get at % -- GHC gets this right wrt the Haskell98 report. Hugs exports it from the Prelude (as does NHC, by the looks of it), which used to be right, but isn't in H98. This could be trivially fixed on the Hugs side, but I'm not sure the resulting breakage would be worth it.
The Haskell98 report says: "In particular, the type Rational is a ratio of two Integer values, as defined in the Rational library."
That's a typo in the Report, it should say the "Ratio library" (Section 6.4, Simon). --sigbjorn

Amanda Clare ajc@aber.ac.uk writes:
Does anyone know how I use Rationals in ghc? In nhc I can just write
let a = b % c
But ghc-5.00.2 gives the error message "Variable not in scope: `%'"
As you noticed, you need to import Ratio to get at % -- GHC gets this right wrt the Haskell98 report. Hugs exports it from the Prelude (as does NHC, by the looks of it), which used to be right, but isn't in H98. This could be trivially fixed on the Hugs side, but I'm not sure the resulting breakage would be worth it.
Of course it would! The whole point of having a report defining Haskell 98 is that implementations should behave the same with the same programmes. If nhc had conformed to the report I don't think Amanda would have had this problem, since nhc would have reported an error from the start. (Although the report typo might have meant she would have had to ask the question, but someone would have had to spot that anyway.) Please, implementors: the fiddly little differences really are important! It's bad for the image if nothing else. Jón PS do the nhc implementors get these messages? It's more on-topic for them than for ghc-users. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk 31 Chalmers Road jf@cl.cam.ac.uk Cambridge CB1 3SZ +44 1223 570179 (after 14:00 only, please!)
participants (2)
-
Jon Fairbairn
-
Sigbjorn Finne