RE: read-ing scientific notation
| GHC is oddly particular about decimal points in "read"-ing in | of Doubles in scientific notation. It seems that read | "3.0e-06" is acceptable but read "3e-06" is not (both read | "3" and read "3.0" work fine as Doubles). It's the same in | nhc and hugs. Perhaps this is some standard somewhere that | Perl doesn't understand? It's true about the Haskell language too, and that's why it's true of Read. The lexical syntax says that 10e3 means 10 e3 (i.e. two lexemes). I don't like this choice, and it could be "fixed" in the Revised H98 report. The current production for float is float -> decimal . decimal[(e | E)[- | +]decimal] I guess we could change that to exponent -> (e|E) [+|-] decimal float -> decimal . decimal [exponent] | decimal exponent It's an unforced change and therefore to be regarded with deep suspicion. I'd be interested in people's views about this. Simon
On Fri, 12 Oct 2001, Simon Peyton-Jones wrote:
| GHC is oddly particular about decimal points in "read"-ing in | of Doubles in scientific notation. It seems that read | "3.0e-06" is acceptable but read "3e-06" is not (both read | "3" and read "3.0" work fine as Doubles). It's the same in (snip) It's an unforced change and therefore to be regarded with deep suspicion. I'd be interested in people's views about this.
I was actually recently caught out by this - I'd assumed that 3e-06 would work (as it does in Modula-3, etc.), and it didn't. Personally, my preference would be for it to mean just the same as 3.0e-06 - it's annoying having to go through my physical constants now adding the rather-redundant ".0"'s everywhere. (-: But, with the sort of parsing I'm doing, "terms" are largely separated by whitespace anyway; maybe if they weren't I'd want things different. -- Mark
The lexical syntax says that 10e3 means 10 e3 (i.e. two lexemes). I don't like this choice, and it could be "fixed" in the Revised H98 report.
What is the likelihood of anyone *intentionally* writing an integer abutted directly with a varid, followed directly by another integer, and no intervening whitespace? Nil, unless you are entering an obfuscated code contest, I reckon. This looks like a good change to me. Regards, Malcolm
The lexical syntax says that 10e3 means 10 e3 (i.e. two lexemes). I don't like this choice, and it could be "fixed" in the Revised H98 report.
What is the likelihood of anyone *intentionally* writing an integer abutted directly with a varid, followed directly by another integer, and no intervening whitespace? Nil, unless you are entering an obfuscated code contest, I reckon. This looks like a good change to me.
Given that someone might well intend f 10 e3 and accidentally write f 10e3, if there's a change at all I'd be happier to make 10e3 erroneous. While that case is probably going eventually to be caught by the type checker, it's better to have mistakes pointed out as soon as possible. I already intensely dislike the fact that f [1..10] mistyped as f [1.10] can get through both syntax and type-checking, so I'd vote against making the syntax more permissive unless someone can prove that all the errors that get through as a result are going to be caught some other way at compile time. Jón -- 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 (4)
-
Jon Fairbairn -
Malcolm Wallace -
Mark Carroll -
Simon Peyton-Jones