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