Here is what I understand about this unsafeRangeSize stuff. 

1.  unsafeIndex has to be in the class, because usually everything else
(unsafeRangeSize, rangeSize, index) is defined in terms of it.

2.  index, rangeSize have to be in the class because that's what Haskell
says

3.  unsafeRangeSize could be declared in the class, but does not have to
be.  It can be defined to use a calls to unsafeIndex, outside the class.
It seems implausible that it a per-type implementation could be much
more efficient than (unsafeIndex b h + 1).

I see Ross has done that already for Hugs, and I propose to go ahead and
do it for GHC in libraries/base/Arr.lhs, unless anyone objects.

Simon


| -----Original Message-----
| From: Simon Marlow
| Sent: 13 April 2005 12:09
| To: Ross Paterson
| Cc: Simon Peyton-Jones; [EMAIL PROTECTED]
| Subject: RE: cvs commit: fptools/libraries/base/GHC Arr.lhs
| 
| On 13 April 2005 11:59, Ross Paterson wrote:
| 
| > On Wed, Apr 13, 2005 at 11:35:42AM +0100, Simon Marlow wrote:
| >> It's because unsafeRangeSize is supposed to have the same meaning
as
| >> rangeSize.  If someone defines an instance of Ix and overrides
| >> rangeSize, then unsafeRangeSize should continue to behave like
| >> rangeSize (remember, unsafeRangeSize isn't part of the exposed
| >> interface of Data.Ix, so clients of that interface can only define
| >> rangeSize).
| >
| > The specification of rangeSize (Report + Erratum):
| >
| >     map index (range (l,u)) == [0..rangeSize (l,u) - 1]
| >
| > constrains it (and unsafeRangeSize) fairly closely.  The text seems
to
| > imply that l and u are the first and last elements of range (l,u),
| > i.e.
| >
| >     index (l,u) l == 0
| >     index (l,u) u == rangeSize (l,u) - 1
| >
| > which would make the default definition correct, and seems to imply
| > that it doesn't need to be a member function.
| 
| But what should you expect to go wrong if your instance violates these
rules?
| 
| It depends on where rangeSize is used; if we used unsafeRangeSize
instead of rangeSize, then we'd
| get different results.  But as far as I can tell, unsafeRangeSize is
only used in some definitions of
| unsafeIndex (eg. instance Ix (a,b)), so in fact it's probably safe.
| 
| Perhaps unsafeRangeSize shouldn't be a method?
| 
| Cheers,
|       Simon
_______________________________________________
Cvs-libraries mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-libraries

Reply via email to