
The Report says that the Enum instance for Ratio uses the same rule as for Float/Double, namely that [a..b] means takeWhile (<= (b+1/2)) [a, a+1, a+2, ...] You may say that the "<=" should be "<" but that's what the Report says. Certainly if you do [1%3..10%3] you'll get more values than your rule suggests. I'm not sure what your rule should be, though. (What about [2%4, ... 20%4]?) Anyway, it's a bit late to change the Report Simon | -----Original Message----- | From: Ferenc Wagner [mailto:wferi@bolyai1.elte.hu] | Sent: 22 October 2002 11:12 | To: haskell-cafe@haskell.org | Subject: Rational sequence | | With GHC-5.02.2, I do | | $ ghci | Prelude> :m Ratio | Ratio> [1%2..10%2] | [1 % 2,3 % 2,5 % 2,7 % 2,9 % 2,11 % 2] | | The question is, why is there 11%2 at the end of the list? | It's inconsistent with the (good) rules for Integer, since | | Ratio> [1,3..10] | [1,3,5,7,9] | | Is this intentional? | Feri. | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe

"Simon Peyton-Jones"
The Report says that the Enum instance for Ratio uses the same rule as for Float/Double,
Now I can see that the revised Report contains more about this than the one on haskell.org. But I still can't see the statement you cited above. Where should I look? On the other hand, I found that 'the instance for Ratio t simply "lifts" the corresponding operations over t.' What does this mean with respect to Enum?
namely that [a..b] means takeWhile (<= (b+1/2)) [a, a+1, a+2, ...]
You may say that the "<=" should be "<" but that's what the Report says.
Well, neither makes more sense to me. For an imprecise type I don't expect precise behaviour.
I'm not sure what your rule should be, though. (What about [2%4, ... 20%4]?)
Rationals are represented precisely, so that well defined precise mathematical rules apply to them: [2%4..20%4] == [1%2..10%2] == [1%2,3%2,5%2,7%2,9%2], that's to say [a..b] = takeWhile (<= b) [a, a+1, a+2, ...] Those fuzzy 1/2-s are inserted solely to 'overcome' the imprecise floating point representation, and make 'simple stupid' programs work and programming newbies happy, aren't they? For serious work they don't count, only create one more peculiarity to observe. Please correct me if I'm mistaken. And please don't feel offended, I suppose that our opinions differ on this point, as shown by a previous thread. Still I don't think things like this promote Haskell, or make it more acceptable for anyone.
Anyway, it's a bit late to change the Report
As I told above, I can't see anything to change, except implementation. If it's only my stupidity, then sorry for the nitpicking. Feri.
participants (2)
-
Ferenc Wagner
-
Simon Peyton-Jones