Rational sequence

Simon Peyton-Jones simonpj@microsoft.com
Thu, 24 Oct 2002 14:59:51 +0100


Folks

The concrete is setting fast, but Ross points out that the instance for
Enum (Ratio a) is inconsistent with that for Enum Float and Enum Double.
(It's strange that these non-integral types are in Enum, but we're stuck
with that.)

All three use 'numericEnumFrom' etc for the enumFrom method, but Float
and Double define succ and pred thus:

	instance Enum Float where
		succ x =3D x+1
		pred x =3D x-1

But Ratio does not... it uses the default method for succ/pred which
gives

	instance Integral a =3D> Enum (Ratio a) where
		succ x =3D fromInt (1 + (toInt x))

Thus (succ (1.5 :: Float)) is 2.5
but   (succ (3%2)) is 2%1

Furthermore, you'd expect that=20
	[x..y]
would mean the same as
	[x,succ x .. y]
and that is true for Float/Double but not for Ratio.

So I propose to modify the instance decl for Ratio by adding explicit
defns for succ/pred just like those in Float/Double. =20

Any objections?

Simon


PS: CUP are typesetting the report now, assuming we can come to happy
agreement about copyright etc.  On that front, the CUP wheels are
grinding, but they grind slow.  I'll emit an update when I know
something useful.