A sample revised prelude for numeric classes

Dylan Thurston dpt@math.harvard.edu
Mon, 12 Feb 2001 13:15:14 -0500


On Mon, Feb 12, 2001 at 07:24:31AM +0000, Marcin 'Qrczak' Kowalczyk wrote:
> Sun, 11 Feb 2001 22:27:53 -0500, Dylan Thurston <dpt@math.harvard.edu> pisze:
> > Reading this, it occurred to me that you could explictly declare an
> > instance of Powerful Integer Integer and have everything else work.
> No, because it overlaps with Powerful a Integer (the constraint on a
> doesn't matter for determining if it overlaps).

Point.  Thanks.  Slightly annoying.

> > > Then the second argument of (^) is always arbitrary RealIntegral,
> > 
> > Nit: the second argument should be an Integer, not an arbitrary
> > RealIntegral.
> 
> Of course not. (2 :: Integer) ^ (i :: Int) makes perfect sense.

But for arbitrary RealIntegrals it need not make sense.

Please do not assume that
  toInteger :: RealIntegral a => a -> Integer
  toInteger n | n < 0 = toInteger negate n
  toInteger 0         = 0
  toInteger n | n > 0 = 1 + toInteger (n-1)
(or the more efficient version using 'even') terminates (in principle)
for all RealIntegrals, at least with the definition as it stands in my
proposal.  Possibly toInteger should be added; then (^) could have the
type you suggest.  For usability issues, I suppose it should.  (E.g.,
users will want to use Int ^ Int.)

OK, I'm convinced of the necessity of toInteger (or an equivalent).
I'll fit it in.

Best,
	Dylan Thurston